Skip to content
  • Tutorials
    • c programming
      • libraries
    • c++
    • Linux
    • Python
    • batch programming
    • Technology
  • IDE
  • Tools
python pathlib create directory if not exists 1

python pathlib create directory if not exists

May 15, 2022 by Anurag batra
try:
    os.makedirs("path/to/directory")
except FileExistsError:
    # directory already exists
    pass

Here is what the above code is Doing:
1. It’s checking if the directory exists.
2. If it doesn’t exist, it creates it.
3. If it does exist, it does nothing.

Categories Python Examples
Post navigation
how to make a bot say hello when a user says hello in discord with python
depth first search
© MyEduKit - 2022 . All Rights Reserved.