Python Forum

Full Version: Delete directories in folder is not working after folder is updated
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I'm having an automated test that is deleting all the projects inside Projects folder.

folder = myPath\Projects\Project1
                         Project2
 

The test executes like this:

deleteProjectsFromFolder,createNewProject,deleteProjectsFromFolder


The code for deleteProjectsFromFolder is this:

        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)
First delete projects from folder works but the second one after new project is created does not delete the directories(projects) anymore. What should I do in this case?Are there some other solutions for this?
Show more of the code. The problem is likely originating elsewhere.
I guess everything else is related to the automation framework itself. The problem I guess the program sits in that directory and after the folder is updated it does not know anymore to execute delete(folder) again.