Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a new Folder with given path [duplicate]

I'm wondering if any of you have created a function to create a folder within a given path.

For Example: NewFolder = ['/projects/Resources/backup_Folder']

like image 841
Victor Aguilar Avatar asked Mar 15 '17 18:03

Victor Aguilar


People also ask

How can we create duplicate file or folder?

Copy and paste files Select the file you want to copy by clicking on it once. Right-click and pick Copy, or press Ctrl + C . Navigate to another folder, where you want to put the copy of the file.

Can you duplicate folders in Windows?

Alternatively, right-click the folder, select Show more options and then Copy. In Windows 10 and earlier versions, right-click the folder and select Copy, or click Edit and then Copy. Navigate to the location where you want to place the folder and all its contents.

How can I safely create a nested directory?

The most common methods to safely create Python Nested Directories are by using the Python pathlib library and the os library module. Before you can work with files in Python, we must compulsorily import these modules into our program.


1 Answers

Use the os library, specifically os.mkdir()

https://docs.python.org/2/library/os.html#os.mkdir

For example,

path = "/usr/temp/foo"
os.mkdir(path)

If the intermediate folders don't exists, use os.makedirs as per Peter Wood's comment

path = "/newfolder1/newfolder2/foo"
os.mkdir(path)
like image 102
Adam Hughes Avatar answered Oct 21 '22 00:10

Adam Hughes