{"record":{"id":"9d97b9dae2682419","repo":"JanDeDobbeleer/oh-my-posh","slug":"unable-to-remove-existing-font-file-s","errorCode":null,"errorMessage":"unable to remove existing font file: %s","messagePattern":"unable to remove existing font file: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/font/install_windows.go","lineNumber":45,"sourceCode":"\tfontsDir := filepath.Join(os.Getenv(\"USERPROFILE\"), \"AppData\", \"Local\", \"Microsoft\", \"Windows\", \"Fonts\")\n\n\tlog.Debugf(\"installing font %s to %s\", font.FileName, fontsDir)\n\n\t// check if the Fonts folder exists, if not, create it\n\tif _, err := os.Stat(fontsDir); os.IsNotExist(err) {\n\t\tif err = os.MkdirAll(fontsDir, 0755); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to create fonts directory: %s\", err.Error())\n\t\t}\n\t}\n\n\tlog.Debug(\"fonts directory exists, proceeding with installation\")\n\n\tfullPath := filepath.Join(fontsDir, font.FileName)\n\t// validate if the font is already installed, remove it in case it is\n\tif _, err := os.Stat(fullPath); err == nil {\n\t\tlog.Debugf(\"font %s already exists, removing it\", fullPath)\n\t\tif err = os.Remove(fullPath); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to remove existing font file: %s\", err.Error())\n\t\t}\n\t}\n\n\tlog.Debugf(\"writing font file to %s\", fullPath)\n\n\terr := os.WriteFile(fullPath, font.Data, 0644)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to write font file: %s\", err.Error())\n\t}\n\n\tlog.Debug(\"font file written successfully, proceeding with registry entry\")\n\n\t// Add registry entry\n\treg := registry.CURRENT_USER\n\tregValue := fullPath\n\n\tlog.Debug(\"opening HKEY_CURRENT_USER for writing (SOFTWARE\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Fonts)\")\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/font/install_windows.go#L27-L63","documentation":"Before writing the new font file, the Windows `install` routine removes a previously installed font with the same filename. This error wraps `os.Remove(fullPath)` failing on that existing file — typically because the font is locked by a running application or the process lacks delete permission.","triggerScenarios":"`os.Stat(fullPath)` succeeds (font already installed), then `os.Remove(fullPath)` returns an error: file in use (loaded by GDI/DirectWrite in a running app), read-only attribute, or ACL denies delete (machine fonts dir without elevation).","commonSituations":"Reinstalling/upgrading a font that Word/Photoshop/your terminal currently has loaded; SYSTEM-owned file in C:\\Windows\\Fonts installed by another admin; read-only attribute set on the old file.","solutions":["Close applications using the font (browsers, editors, the terminal itself) and retry","Run elevated if the existing file is in C:\\Windows\\Fonts","Clear the read-only attribute: `attrib -r \"<fullPath>\"` then retry","Reboot (or restart explorer.exe) to release GDI font handles, then reinstall","Manually delete the old font via Settings > Fonts, then run the installer again"],"exampleFix":"// before\nPS> oh-my-posh font install FiraCode   # file locked by running app\n// after: close apps / release handle, or\nPS> attrib -r \"$env:LOCALAPPDATA\\Microsoft\\Windows\\Fonts\\FiraCode-Regular.ttf\"\nPS> oh-my-posh font install FiraCode","handlingStrategy":"validation","validationCode":"# pre-check that the existing font file is deletable\n$path = \"$env:LOCALAPPDATA\\Microsoft\\Windows\\Fonts\\FiraCode-Regular.ttf\"\nif (Test-Path $path) {\n  try { $fs=[IO.File]::Open($path,'Open','ReadWrite','None'); $fs.Close() }\n  catch { Write-Error \"Font file is locked: $path\"; exit 1 }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Close apps that load fonts (browsers, editors, terminal) before reinstalling","Clear read-only attributes on font files before automated reinstalls","Run elevated when replacing fonts in C:\\Windows\\Fonts"],"tags":["windows","filesystem","file-locked"],"backgroundTag":"file-in-use","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}