OS Module
Import OS Module
First, we need to import the OS Module in our project. So for using the OS Module, we need to add using the โimportโ statement. Along with that, we are gonna import a time module to make our program wait for some time using the sleep method.
Create a Function for Create Folders
As we know that for creating the function in Python we have to use โdefโ keyword to define a function.
So letโs create a new function โcreateFolders(address)โ which accepts one argument as the address where we need to create folders.
So for this example letโs create 10 directories or folders using OS built-in Module.
Create a Function for Create Files
Since we have declared a function which creates 10 folders at address which we passed as an argument.
Now letโs create a new function for creating files named it as โcreateFiles(arg)โ which accepts one argument as the address where we need to create files.
So for this example letโs create 10 files using OS Module.
Create a Function for Rename Files
Now we have already defined the function for creating folders and files, so now letโs create a new function for rename the files and folders.
Also Read => Flask Python Basic Application Tutorial [ Part-1 ]
As we already created the folders with โ-Dirโ at last so now what we want is to replace this โDirโ with Folder.
Create Main Function Code
Now we have created all the basic functions of the built-in Module. Now what we want is to create a main function to call them to show their functionality.
And also we are gonna use the time module which has sleep(seconds) in this main function to make a pause while creating and renaming files or folders.
Output
Source Code :
Last updated