I'm trying to delete a big number of folders in some code I am writing in Python 2.7, the folders to be deleted are in the same folder than the code I'm running. To do this I use subprocess in the following way:
import subprocess
def runsafe(job,args):
jobs=[job];
for arg in args:
jobs.append(arg)
proc=subprocess.Popen(jobs,stdout=subprocess.PIPE)
return proc.stdout.readlines()
if __name__=="__main__":
runsafe("rm",["-r","./*/"])
If I do this the code doesn't delete any folders. Obviously, if I write rm -r ./*/
in my terminal all the folders inside the folder where I'm running the code are deleted. Also if I change runsafe("rm",["-r","./*/"])
in my code for runsafe("rm",["-r","./foo/"])
(where foo is one of the folders to be deleted) the code works fine and deletes the desired folder.
How can I delete all the folders at once? Why doesn't it work if I use * to indicate that I want to delete all the folders?