How do you create a new directory in Python?
a) By using the os.mkdir() function
b) By using the os.makedirs() function
c) By using the shutil.mkdir() function
d) By using the os.create_dir() function
Answer:
a) By using the os.mkdir() function
Explanation:
To create a new directory in Python, you can use the os.mkdir()
function. This function takes the path of the directory you want to create as an argument and creates the directory at that location.
import os
# Example of creating a new directory
os.mkdir("new_directory")
In this example, the os.mkdir()
function creates a new directory named new_directory
in the current working directory.
Creating directories programmatically is useful for organizing files, setting up directory structures for applications, or creating temporary directories for data processing.