create folders in python overwright existing 1

create folders in python overwright existing

import os
import shutil

path = 'path_to_my_folder'
if not os.path.exists(path):
    os.makedirs(path)
else:
    shutil.rmtree(path)           # Removes all the subdirectories!
    os.makedirs(path)

Here is what the above code is Doing:
1. Check if the path exists.
2. If it does, delete it and create a new one.
3. If it doesn’t, create it.

Similar Posts