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.
Create a new directory stuff inside of a new directory some, which should live
inside the root directory ( / ).
Feeling stuck? We'd love to hear what's confusing so we can improve this lesson. Please share your questions and feedback.