Last active
September 6, 2020 16:15
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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