{"record":{"id":"f30bbcb679a07676","repo":"ipfs/kubo","slug":"s-mfs-destination-q-is-not-a-directory","errorCode":null,"errorMessage":"%s: MFS destination %q is not a directory","messagePattern":"(.+?): MFS destination %q is not a directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/add.go","lineNumber":600,"sourceCode":"\t\t\t\t\t\ttoFilesStr = \"/\"\n\t\t\t\t\t}\n\t\t\t\t\ttoFilesDst, err := checkPath(toFilesStr)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\terrCh <- fmt.Errorf(\"%s: %w\", toFilesOptionName, err)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tdstAsDir := toFilesDst[len(toFilesDst)-1] == '/'\n\n\t\t\t\t\tif dstAsDir {\n\t\t\t\t\t\tmfsNode, err := mfs.Lookup(ipfsNode.FilesRoot, toFilesDst)\n\t\t\t\t\t\t// confirm dst exists\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\terrCh <- fmt.Errorf(\"%s: MFS destination directory %q does not exist: %w\", toFilesOptionName, toFilesDst, err)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// confirm dst is a dir\n\t\t\t\t\t\tif mfsNode.Type() != mfs.TDir {\n\t\t\t\t\t\t\terrCh <- fmt.Errorf(\"%s: MFS destination %q is not a directory\", toFilesOptionName, toFilesDst)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// if MFS destination is a dir, append filename to the dir path\n\t\t\t\t\t\ttoFilesDst += gopath.Base(addit.Name())\n\t\t\t\t\t}\n\n\t\t\t\t\t// error if we try to overwrite a preexisting file destination\n\t\t\t\t\tif fileAddedToMFS && !dstAsDir {\n\t\t\t\t\t\terrCh <- fmt.Errorf(\"%s: MFS destination is a file: only one entry can be copied to %q\", toFilesOptionName, toFilesDst)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t_, err = mfs.Lookup(ipfsNode.FilesRoot, gopath.Dir(toFilesDst))\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\terrCh <- fmt.Errorf(\"%s: MFS destination parent %q %q does not exist: %w\", toFilesOptionName, toFilesDst, gopath.Dir(toFilesDst), err)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n","sourceCodeStart":582,"sourceCodeEnd":618,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/add.go#L582-L618","documentation":"`ipfs add --to-files <dst>` requires the MFS destination to be a directory when the destination path ends with '/'. The add command looked up the target MFS node and found it is not a directory (mfs.TDir), so it cannot append the added file's name beneath it. This is a pre-flight destination-type check in the --to-files handling, thrown before any MFS write occurs.","triggerScenarios":"Run `ipfs add --to-files /somepath/` (trailing slash forces directory interpretation) where /somepath exists in MFS but is a regular file, not a directory; the lookup succeeds but mfsNode.Type() != mfs.TDir, producing '<dst>: MFS destination \"/somepath/\" is not a directory'.","commonSituations":"Users pass an existing MFS file path with a trailing slash believing it creates the file; scripts reuse a destination path that was previously created as a file; confusion between 'destination is the file itself' vs 'destination is the parent directory to place it in'.","solutions":["Remove the trailing slash from --to-files to target a file destination directly, e.g. --to-files /path/file.txt","Ensure the destination directory exists in MFS first: ipfs files mkdir -p /path/dir","Verify the destination type with `ipfs files stat /path` and pick the correct path"],"exampleFix":"// before\nipfs add --to-files /docs/ myfile.txt   # /docs is an existing MFS file\n// after\nipfs files mkdir -p /docs\nipfs add --to-files /docs/ myfile.txt","handlingStrategy":"validation","validationCode":"// shell pre-check before ipfs add --to-files /path/\ntype=$(ipfs files stat /path | head -1)\n[ \"$type\" = \"directory\" ] || ipfs files mkdir -p /path","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use a trailing slash on --to-files when the destination is a known MFS directory","Create destination directories with `ipfs files mkdir -p` first","Check `ipfs files stat` on the destination before scripting the add"],"tags":["cli","mfs","to-files","path"],"backgroundTag":"mfs-destination-not-directory","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"}