ipfs/kubo · error

path is a directory, use -r to remove directories

Error message

path is a directory, use -r to remove directories

What it means

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.

Source

Thrown at core/commands/files.go:1472

			if err == os.ErrNotExist {
				return nil
			}
			return err
		}
		return pdir.Flush()
	}

	// get child node by name, when the node is corrupted and nonexistent,
	// it will return specific error.
	child, err := pdir.Child(name)
	if err != nil {
		return err
	}

	switch child.(type) {
	case *mfs.Directory:
		if !dashr {
			return fmt.Errorf("path is a directory, use -r to remove directories")
		}
	}

	err = pdir.Unlink(name)
	if err != nil {
		return err
	}

	return pdir.Flush()
}

// getPrefix builds a cid.Builder from CLI flags, falling back to importCfg
// when provided. Returns (nil, nil) when neither CLI nor config set a value.
func getPrefix(req *cmds.Request, importCfg *config.Import) (cid.Builder, error) {
	cidVer, cidVerSet := req.Options[filesCidVersionOptionName].(int)
	hashFunStr, hashFunSet := req.Options[filesHashOptionName].(string)

	if cidVerSet || hashFunSet {

View on GitHub (pinned to 329838acdf)

Solutions

  1. Add -r to remove the directory and its contents: `ipfs files rm -r /path/to/dir`.
  2. If only a file was intended, double-check the path points at a file, not a directory.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at core/commands/files.go:1472 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/21458047527b8476. Report an issue: GitHub.