{"record":{"id":"2370444061296bff","repo":"coreybutler/nvm-windows","slug":"failed-to-create-destination-directory-w","errorCode":null,"errorMessage":"failed to create destination directory: %w","messagePattern":"failed to create destination directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utility/rename.go","lineNumber":59,"sourceCode":"\t\treturn fmt.Errorf(\"failed to remove source: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// copyFile copies a single file from source (old) to destination (new).\nfunc copyFile(old, new string) error {\n\tsrcFile, err := os.Open(old)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open source file: %w\", err)\n\t}\n\tdefer srcFile.Close()\n\n\t// Ensure destination directory exists\n\tdestDir := filepath.Dir(new)\n\terr = os.MkdirAll(destDir, os.ModePerm)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination directory: %w\", err)\n\t}\n\n\tdestFile, err := os.Create(new)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination file: %w\", err)\n\t}\n\tdefer destFile.Close()\n\n\t_, err = io.Copy(destFile, srcFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to copy data: %w\", err)\n\t}\n\n\t// Copy file permissions\n\tinfo, err := srcFile.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get source file info: %w\", err)\n\t}","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/utility/rename.go#L41-L77","documentation":"In copyFile(), after opening the source, os.MkdirAll(filepath.Dir(new), os.ModePerm) prepares the destination directory tree. This error means that directory creation failed — typically because a component of the parent path exists as a FILE (ENOTDIR), a permission denial, or an invalid path (illegal characters, trailing spaces).","triggerScenarios":"copyFile where the destination's parent path collides with an existing regular file, the destination drive is unavailable/read-only, or the path contains characters Windows rejects (e.g. reserved names like CON, NUL).","commonSituations":"Destination node version directory partially created by an earlier failed install so a directory name is occupied by a file; running non-elevated against C:\\Program Files; mistyped NVM_HOME pointing at a nonexistent or read-only drive.","solutions":["Check the wrapped error: 'The system cannot find the path specified' usually means a parent component is a file — remove the conflicting file.","Verify NVM_HOME/NVM_SYMLINK point to writable locations and the drive is mounted.","Run elevated when writing under protected directories.","Retry the nvm command after cleaning the partially-created destination directory."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure the destination parent is a directory, not blocked by a file\nfunc ensureDir(p string) error {\n    if info, err := os.Stat(p); err == nil && !info.IsDir() {\n        return fmt.Errorf(\"%s exists and is not a directory\", p)\n    }\n    return os.MkdirAll(p, 0o755)\n}","typeGuard":null,"tryCatchPattern":"if err := copyAcrossDrives(old, new); err != nil && strings.Contains(err.Error(), \"destination directory\") {\n    // remove the conflicting file at the reported path, then retry\n    os.Remove(filepath.Dir(new))\n    err = copyAcrossDrives(old, new)\n}","preventionTips":["Clean partially-created destination trees before retrying.","Point NVM_HOME at a writable drive you own.","Validate path components contain no Windows-illegal characters."],"tags":["filesystem","mkdir","copy","windows","configuration"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}