Delete directories in folder is not working after folder is updated - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Delete directories in folder is not working after folder is updated (/thread-16072.html) |
Delete directories in folder is not working after folder is updated - asheru93 - Feb-13-2019 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? RE: Delete directories in folder is not working after folder is updated - stullis - Feb-13-2019 Show more of the code. The problem is likely originating elsewhere. RE: Delete directories in folder is not working after folder is updated - asheru93 - Feb-13-2019 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. |