MFS allows you to remove files or directories using the files.rm
method:
await ipfs.files.rm(...paths, [options])
paths
are one or more paths to remove.
By default, if you attempt to remove a directory that still has contents, the request will fail. To remove a directory and everything contained in it, you'll need to use the option { recursive: true }
.
// remove a file
await ipfs.files.rm('/my/beautiful/file.txt')
// remove multiple files (note the two acceptable formats with or without [ ])
await ipfs.files.rm('/my/beautiful/file.txt', '/my/other/file.txt')
await ipfs.files.rm(['/my/beautiful/file.txt', '/my/other/file.txt'])
// remove a directory and its contents
await ipfs.files.rm('/my/beautiful/directory', { recursive: true })
// remove a directory only if it is empty
await ipfs.files.rm('/my/beautiful/directory')
Remove your some
directory, including the stuff
directory and all of its contents. This action should leave your root directory empty.
Feeling stuck? We'd love to hear what's confusing so we can improve this lesson. Please share your questions and feedback.