Method 1: Using shutil. Using copyfile() method of shutil library we can easily copy a file from one location to other location. It takes 2 arguments the source path where the file that needs to be copied exist and the destination path where file is needed to be copied.
For python 3.2 and above, you can use os. makedirs . Using method makedirs() from module os , a nested directory can be created in a simple way. The parameter passed is the nested directory we wanted to create.
makedirs() method in Python is used to create a directory recursively. That means while making leaf directory if any intermediate-level directory is missing, os. makedirs() method will create them all. Suppose we want to create directory 'ihritik' but Directory 'GeeksForGeeks' and 'Authors' are unavailable in the path.
With the os module, if you want to create just a single directory, you can use os. mkdir() (make directory) with the directory name, which creates a single subdirectory with the given name.
Try os.makedirs
instead, if you want to create a tree of directories in one call.
I tried the above on Linux using Python 2.6.6, but had to ensure that the string ended with a '/' (or '\', on Windows). E.g.
os.makedirs('folder/subfolder/')
Otherwise only 'folder' was created.
I think you want the os.makedirs() function, which can create intermediate directories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With