Create a new dir in python 3
You can create a new directory in Python 3 using the os
module. Here's an example:
import os
# Create a new directory
os.mkdir("my_new_dir")
This will create a new directory called "my_new_dir" in the current working directory.
If you want to create a directory in a specific location, you can specify the full path:
os.mkdir("/path/to/my/new/dir")
Make sure to replace "/path/to/my/new/dir" with the actual path where you want to create the directory.
If the directory already exists, os.mkdir()
will raise a FileExistsError
. If you want to avoid this error, you can use the os.makedirs()
function, which will create the directory and all its parents if they don't exist:
os.makedirs("my/new/dir")
This will create the directory "my/new/dir" and all its parents if they don't exist.
Note: On Windows, you may need to use os.makedirs()
instead of os.mkdir()
to create directories with spaces in their names.