{"record":{"id":"4cf9307549a3d53a","repo":"gohugoio/hugo","slug":"createpath-already-exists-but-not-a-directory","errorCode":null,"errorMessage":"{createpath} already exists but not a directory","messagePattern":"(.+?) already exists but not a directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"create/skeletons/skeletons.go","lineNumber":99,"sourceCode":"\t\t\"title\": \"{{ replace .File.ContentBaseName \\\"-\\\" \\\" \\\" | title }}\",\n\t\t\"date\":  \"{{ .Date }}\",\n\t\t\"draft\": true,\n\t}\n\n\terr = createDefaultArchetype(sourceFs, createpath, defaultArchetype, format)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn copyFiles(createpath, sourceFs, themeFs)\n}\n\n// CreateProject creates a project skeleton.\nfunc CreateProject(createpath string, sourceFs afero.Fs, force bool, format string) error {\n\tformat = strings.ToLower(format)\n\tif exists, _ := helpers.Exists(createpath, sourceFs); exists {\n\t\tif isDir, _ := helpers.IsDir(createpath, sourceFs); !isDir {\n\t\t\treturn errors.New(createpath + \" already exists but not a directory\")\n\t\t}\n\n\t\tisEmpty, _ := helpers.IsEmpty(createpath, sourceFs)\n\n\t\tswitch {\n\t\tcase !isEmpty && !force:\n\t\t\treturn errors.New(createpath + \" already exists and is not empty. See --force.\")\n\t\tcase !isEmpty && force:\n\t\t\tvar all []string\n\t\t\tfs.WalkDir(projectFs, \".\", func(path string, d fs.DirEntry, err error) error {\n\t\t\t\tif d.IsDir() && path != \".\" {\n\t\t\t\t\tall = append(all, path)\n\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t})\n\t\t\tall = append(all, filepath.Join(createpath, \"hugo.\"+format))\n\t\t\tfor _, path := range all {\n\t\t\t\tif exists, _ := helpers.Exists(path, sourceFs); exists {","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/create/skeletons/skeletons.go#L81-L117","documentation":"CreateProject (the `hugo new site` scaffold) requires its createpath to be either absent or a directory. If the path exists but is a regular file, scaffolding cannot proceed because it would need to create directories there.","triggerScenarios":"`hugo new site path` where `path` is an existing file (e.g. a file named the same as the requested site).","commonSituations":"The requested site name collides with an existing file; pointing new site at a path that is already a file.","solutions":["Remove or rename the conflicting file.","Use a different target path that is not a file."],"exampleFix":"// before\nhugo new site ./site   # ./site is a file\n// after\nrm ./site\nhugo new site ./site","handlingStrategy":"validation","validationCode":"// Ensure createpath is absent or a directory\nif fi, err := os.Stat(createpath); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"%s is a file, not a directory\", createpath)\n}","typeGuard":"func isAbsentOrDir(createpath string) bool {\n    fi, err := os.Stat(createpath)\n    return os.IsNotExist(err) || (err == nil && fi.IsDir())\n}","tryCatchPattern":null,"preventionTips":["Avoid site names that collide with existing files.","Check the target path type before scaffolding."],"tags":["hugo","cli","filesystem","scaffold"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}