Wednesday 15 September 2010

directory - Delete multiple directories in python -


In Python, I understand that I can delete several files with the same name using the following command:

Can be removed from Shutil.rmtree ('/ path / to / dir') - and this command will remove the directory, even if the directory is not empty. On the other hand, os.rmdir () needs to be empty.

I really want to delete several directories with the same name, and if they are not empty, then I'm looking for something like shutil.rmtree ('directory _ *')

Is there any way to do this with python?

You have all the pieces: iterates , Rmtree () deletes: path to glob.glob ("directory_ *")

 : shutil.rmtree (path)   < P> This  OSError  if a globbed path returns a file name, or for any other reason that  rmtree ()  may fail, you handle the error during the error view You can, once you decide how you want to handle errors, it is not understandable to add this error It comes, unless you do not know what you want to do with the error, so I have left to deal with the error.   

No comments:

Post a Comment