Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python mkdir to make folder with subfolder? [duplicate]

People also ask

How do I copy a subfolder in Python?

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.

How do I create a sub folder in Python?

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.

How do I make a directory recursive in Python?

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.

Does os mkdir create subdirectories?

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.