Mutable File System | Lesson 7 of 11

Create a directory

We've learned how to add files to the root directory, but how can we make a new directory? Again, the process is very similar to what you may have experienced on the command line on your own computer.

The MFS method files.mkdir creates a new directory at a specified path. For example, to add a directory images to our root directory ( / ), we could do this:

await ipfs.files.mkdir('/images')

An optional parents property, which defaults to false, specifies whether any parent directories in the given path should be created if they don't already exist. We didn't need that above, because the new images directory was a direct child of an existing directory ( / ). However, if we instead wanted to created a new directory nested under others that don't yet exist, we'd need to explicitly set the value of parents to true, like so:

await ipfs.files.mkdir('/my/beautiful/images', { parents: true })

Gotcha! Although the goal of creating a missing path is similar, notice how we use the { parents: true } option with files.mkdir instead of the { create: true } option that was available with files.write.

Try it!

Create a new directory stuff inside of a new directory some, which should live inside the root directory ( / ).

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.