Skip to content Skip to sidebar Skip to footer

How To Delete Files / Directories After Subprocess Is Done With Them?

I am using Watchdog to monitor a directory. If any new directories are added, I want to start subprocesses on those 'Source' directories and call a program anon_local on the direct

Solution 1:

This can be done with shutil's rmtree function.

So long as PATH is the directory you want deleted, just check to make sure your subprocess has finished, and then just run shutil.rmtree(PATH)

If you need to wait until your subprocess is done, you can accomplish this by calling .poll() on your proc and waiting for it to return None. For example:

while proc.poll() == None:  # .poll() will return a value once it's complete. 
    time.sleep(1)
[then remove your directory here]

Post a Comment for "How To Delete Files / Directories After Subprocess Is Done With Them?"