8.3 Creating and removing directories
mkdir creates a single directory below an existing parent. If I am
in src
, then
os.mkdir("cookie-recipes")
creates the src/cookie-recipes
directory.
Use rmdir to remove it.
os.rmdir("cookie-recipes")
Suppose we want to create two new directories under src
,
first the recipes
subdirectory, and then cookies
within that. You cannot do it with one call to mkdir:
os.mkdir("recipes/cookies")
FileNotFoundError: The system cannot find the path specified:
'recipes/cookies'
To use mkdir, you could make two calls:
os.mkdir("recipes")
os.mkdir("recipes/cookies")
Alternatively, use makedirs. It creates any necessary intermediate directories.
os.makedirs("recipes/cookies")
Exercise 8.2
Now that you have created recipes/cookies
, what does