Python Forum
create a new directory if not already exists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
create a new directory if not already exists
#2
if you use pathlib, it's simple
>>> from pathlib import Path
>>> CurrentDir = Path('.')
>>>
>>> Newdir = CurrentDir / 'newdir'
>>> Newdir.mkdir(exist_ok=True)
newdir will only be created if it doesn't exist
Reply


Messages In This Thread
RE: create a new directory if not already exists - by Larz60+ - Aug-28-2019, 07:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  create a default path with idle to a specific directory greybill 0 893 Apr-23-2023, 04:32 AM
Last Post: greybill
  p]Why os.path.exists("abc/d") and os.path.exists("abc/D") treat same rajeev1729 1 2,201 May-27-2020, 08:34 AM
Last Post: DeaD_EyE
  Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 2,379 Apr-29-2020, 06:45 PM
Last Post: nisusavi
  Create a directory structure across many servers metro17 1 1,777 Nov-05-2019, 03:35 PM
Last Post: Larz60+
  Help repeately prompting for directory name if it already exists. hikerguy62 3 2,430 Aug-05-2019, 01:43 PM
Last Post: ichabod801
  Python Directory and File Create Error basic_learner 1 2,438 Dec-16-2018, 11:03 AM
Last Post: buran
  Windows/DOS python script cannot create a directory name beginning an @ at-sign LucRhan 6 6,112 May-08-2017, 08:03 PM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020