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