Skip to content

Instantly share code, notes, and snippets.

@SahbiOuali13
Last active September 6, 2020 16:15
Show Gist options
  • Save SahbiOuali13/5c55954116987938f5fcd68dcf028139 to your computer and use it in GitHub Desktop.
Save SahbiOuali13/5c55954116987938f5fcd68dcf028139 to your computer and use it in GitHub Desktop.
- Add path to a specified folder in project. - Create new folder with argument exist_ok. - Remove a folder after checking if it exists.
# add path to a specified folder in project
import os
chemin = r"C:\Users\ouali\OneDrive\Bureau\Formations\Formation Python\la-formation-complete-python-master\test"
folder = os.path.join(chemin, "dossier")
print(folder)
# Create new folder, works fine if the folder already exists.
os.makedirs(folder, exist_ok=True)
# Remove a folder. Unlike makedirs you need to check if the folder already exists.
if os.path.exists(folder)
os.removedirs(folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment