Learning how to interact with a file system is a very valuable programming skill. Many programs need to be capable of reading and writing files and folders to various file systems. The Python language has a library called "os," which provides functionality for creating folders. The "os" library can create folders for the Windows or Unix file systems. The syntax for creating folders in Python is easy to learn and can greatly increase you programming capability.
Open the IDLE text editor that comes with the Python programming language. A blank source-code file opens in the main editor window.
Import the "os" library by writing the following line of code at the top of the page:
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'
Make a directory using the "mkdir" function. You pass in the directory name variable like this:
Run the program by pressing the F5 key. A new directory named "test" is created in the same directory as your source code file.
How to Create a Folder in Windows
Users can create folders several ways in Windows and the following steps will describe some of the most common ones. A folder...