How to avoid “WindowsError: [Error 5] Access is denied”

后端 未结 7 1790
遥遥无期
遥遥无期 2020-12-06 05:12

There\'s the script to re-create folder:

# Remove folder (if exists) with all files
if os.path.isdir(str(os.path.realpath(\'..\') + \"\\\\my_folder\")):
             


        
7条回答
  •  庸人自扰
    2020-12-06 05:14

    Permissions might be the problem, but I had the same problem '[Error 5] Access is denied' on a os.rename() and a simple retry-loop was able to rename the file after a few retries.

    for retry in range(100):
        try:
            os.rename(src_name,dest_name)
            break
        except:
            print "rename failed, retrying..."
    

提交回复
热议问题