Yesterday there was a need to delete files in a directory with a Python script. Got into some trouble.
Using the Shutil.rmtree (dir) function, this function can delete the contents of the directory, while Shutil.rmdir (dir) can only delete the empty directory.
1, a delete on the error, the final suspicion is the account permissions issues, change the permissions of the account, you can delete some files, but there are files can not be deleted
2, in the online search may be due to the file attributes of the problem, if not deleted files are read-only. If you want to delete these files, you need to modify their properties first.
Shutil module is not similar to the function, so that their own modeled shutil.rmtree function to write a, before deleting the file before the first os.chmod (file, Stat. S_iwrite) Just a little bit better.
Remember to import the OS, SYS, Stat.
Python does not use much, but some of the permissions problems really took a while to figure it out.
Python script File Delete