|if not os.path.exists(directory):|
|print ('Error: Creating directory. ' + directory)|
|# Creates a folder in the current directory called data|
Oct 25, 2019
Nov 28, 2019
you can change your directory by os.chdir
Jan 30, 2020
May 16, 2020
Thank you very much..... keithweaver
if anybody facing issue while creating the folder, followed with an error message like this
SyntaxError: unexpected character after line continuation character
please just duplicate with a backslash for the directory you want to create. Here I want to create a Temp folder in web_scrapper folder
Jul 9, 2020
Isn't this all already done by
import os os.mkdirs(directory, exist_ok = True)
exist ok = Truechecks for existence and makes dir created if not existing
OSErrors from the os package will do the error messaging ...
You're right @gwangjinkim. Just switch mkdirs to makedirs and it's good to go.
import os os.makedirs(directory, exist_ok = True)
Jul 9, 2020
@EricHedengren thanks! True! I always have to look this up anew.
Jul 17, 2020
if i would like to create two folders in single directory how to do that
Jul 19, 2020
@khu17jain Write two makedirs statements to the same location. For loop it if you have a lot.
Jan 26, 2021
best code I have ever found, thx!
Mar 3, 2021
Jun 9, 2021
how to create a folder with name in format yyyy-mm-dd from any year to today
Sep 19, 2021
thank you man ``
Dec 23, 2021
Great! Thanks so much!
Apr 3, 2022
Thank you, very useful and helped me understand the command.
Thank you! :)