I have a list of folders with files in the following path: C:\AutoTest\engine\Scv\Projects
In the Projects folder there are folders with files. E.g. Projects\selenium_project1\files Projects\Python_project1\files etc.
I would like to delete all the folders from the Projects folders and files. e.g. I would like to delete selenium_project1\files and Python_project1\files etc.
I have found the following code to delete files. I am not sure if this will do it correctly. Will the code below delete the folders and files from the Projects directory?
import os, shutil
folder = '/path/to/folder'
for the_file in os.listdir(folder):
file_path = os.path.join(folder, the_file)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
except Exception as e:
print(e)
Thanks, Riaz
os.unlink(file_path)withprint(file_path)and see what would be deleted? And no, it won't delete the folders, only the files.