Python Forum
Delete directories in folder is not working after folder is updated
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete directories in folder is not working after folder is updated
#1
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?
Reply
#2
Show more of the code. The problem is likely originating elsewhere.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Deleting Windows temp folder Raysz 7 371 Apr-02-2024, 12:36 PM
Last Post: Raysz
  Help with creating folder and "virtual environment" AudunNilsen 1 210 Mar-21-2024, 04:41 AM
Last Post: deanhystad
  Organization of project directories wotoko 3 417 Mar-02-2024, 03:34 PM
Last Post: Larz60+
Question How to add Python folder in Windows Registry ? Touktouk 1 236 Feb-20-2024, 01:04 PM
Last Post: DeaD_EyE
  Create dual folder on different path/drive based on the date agmoraojr 2 423 Jan-21-2024, 10:02 AM
Last Post: snippsat
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 522 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  problem in import module from other folder akbarza 5 1,380 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  Reading a file name fron a folder on my desktop Fiona 4 889 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt
  Rename files in a folder named using windows explorer hitoxman 3 729 Aug-02-2023, 04:08 PM
Last Post: deanhystad
  Rename all files in a folder hitoxman 9 1,472 Jun-30-2023, 12:19 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020