{"record":{"id":"21458047527b8476","repo":"ipfs/kubo","slug":"path-is-a-directory-use-r-to-remove-directories","errorCode":null,"errorMessage":"path is a directory, use -r to remove directories","messagePattern":"path is a directory, use -r to remove directories","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/files.go","lineNumber":1472,"sourceCode":"\t\t\tif err == os.ErrNotExist {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\treturn err\n\t\t}\n\t\treturn pdir.Flush()\n\t}\n\n\t// get child node by name, when the node is corrupted and nonexistent,\n\t// it will return specific error.\n\tchild, err := pdir.Child(name)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tswitch child.(type) {\n\tcase *mfs.Directory:\n\t\tif !dashr {\n\t\t\treturn fmt.Errorf(\"path is a directory, use -r to remove directories\")\n\t\t}\n\t}\n\n\terr = pdir.Unlink(name)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn pdir.Flush()\n}\n\n// getPrefix builds a cid.Builder from CLI flags, falling back to importCfg\n// when provided. Returns (nil, nil) when neither CLI nor config set a value.\nfunc getPrefix(req *cmds.Request, importCfg *config.Import) (cid.Builder, error) {\n\tcidVer, cidVerSet := req.Options[filesCidVersionOptionName].(int)\n\thashFunStr, hashFunSet := req.Options[filesHashOptionName].(string)\n\n\tif cidVerSet || hashFunSet {","sourceCodeStart":1454,"sourceCodeEnd":1490,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/files.go#L1454-L1490","documentation":"In removePath, the child resolved by pdir.Child(name) is an *mfs.Directory but the -r/--recursive flag was not supplied, so the removal is refused to prevent accidental recursive deletion. The path exists and is valid; only the missing recursive flag triggers the error.","triggerScenarios":"Thrown at core/commands/files.go:1472 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add -r to remove the directory and its contents: `ipfs files rm -r /path/to/dir`.","If only a file was intended, double-check the path points at a file, not a directory."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}