Skip to content

Instantly share code, notes, and snippets.

@keithweaver
Created March 10, 2017 03:42
Show Gist options
  • Save keithweaver/562d3caa8650eefe7f84fa074e9ca949 to your computer and use it in GitHub Desktop.
Save keithweaver/562d3caa8650eefe7f84fa074e9ca949 to your computer and use it in GitHub Desktop.
Create a folder with Python
import os
def createFolder(directory):
try:
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
print ('Error: Creating directory. ' + directory)
# Example
createFolder('./data/')
# Creates a folder in the current directory called data
@eric-hedengren
Copy link

@khu17jain Write two makedirs statements to the same location. For loop it if you have a lot.

@tzuhungbrian
Copy link

best code I have ever found, thx!

@JeremyMeissner
Copy link

Thank you!

@Hemantphareesh
Copy link

how to create a folder with name in format yyyy-mm-dd from any year to today

@DanialBahrizadeh
Copy link

thank you man ``

@SaberKazemii
Copy link

Great! Thanks so much!

@lucasgcruz
Copy link

Thank you, very useful and helped me understand the command.

@sourcecodemage
Copy link

NIce! Thanks for posting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment