0

I have a folder that contains a sub-folder and set of text files. I am trying to delete the sub-folder using the below code

Path = '/Desktop/foldername/'
folder = 'Path/'
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)
        elif os.path.isdir(file_path): shutil.rmtree(file_path)
    except Exception as e:
        print(e)

I keep getting an error folder does not exist. Could anyone advice as to where am I going wrong. Thanks.

Kevin Nash
  • 1,511
  • 3
  • 18
  • 37

0 Answers0