How to Create a Folder in Python
Instructions
1Open the IDLE text editor that comes with the Python programming language. A blank source-code file opens in the main editor window.
2
Import the "os" library by writing the following line of code at the top of the page:
import os
3
Declare a variable that will hold the name and path of the folder. You can leave out the path and just write a folder name, but this will create the folder in the same directory as your source code. By specifying a path, you can create the folder anywhere. For example, you could write this to create a folder named "test" on the C: drive:
directoryPath = r'C:\test'
4
Make a directory using the "mkdir" function. You pass in the directory name variable like this:
os.mkdir(directoryPath)
5
Run the program by pressing the F5 key. A new directory named "test" is created in the same directory as your source code file.
Source...