ProtoSchool

ProtoSchool

Interactive tutorials on decentralized web protocols

Mutable File System | Lesson 11 of 11

Remove a file or directory

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')

not yet startedTry it!

Remove your some directory, including the stuff directory and all of its contents. This action should leave your root directory empty.

Step 1: Upload files
Step 2: Update code
View SolutionReplace with SolutionClear Default Code
Upload file(s) and update the code to complete the challenge.
You must upload a file before submitting.