-2

So I'm moving a lot of files within folders to the layer above all the folders. Essentially what I need to happen is if a file was removed from a folder (to the layer above), then delete the folder it was removed from. Something like:

    for file in files:
        print(file)
        shutil.move(file, downloads_path)
        moved = shutil.move(file, downloads_path)
            if moved is True:
                os.remove(downloads_folder_path)

1 Answers1

0

shutil.move will return you a string of the new file name if successful and raise an Exception if either the source or the target wasn't found.

So actually there is no need to check for its return value at all. You can just proceed with moving everything and then delete the original folder.

Simon Ertl
  • 43
  • 6