我用py2exe编译了一个小的重命名程序。每当我运行可执行文件时,我都会收到以下错误:"第17行,在WindowsError中:[error 5]访问被拒绝"。该程序在python中断器中运行良好,但不能作为EXE运行。我已经尝试运行具有管理权限的可执行文件,但我得到了相同的结果。下面是第17行,有人知道为什么会这样吗?谢谢。
for filename in filenames:
os.rename(os.path.join(path, filename), os.path.join(path, filename.replace(cur_Name, new_Name)))
我最近有这个,当我试图删除一堆文件,第一个是一个只读文件。我只是右键单击它并勾选"只读"。这解决了我的错误
出于兴趣,下面是我的程序:
#This matches (1) files and deletes them IF there is an original of the same file size.
import os
path = "e:\"
for root, dirs, files in os.walk(path):
for lastfile in files:
if lastfile.find(' (1).') > -1:
onepos = lastfile.find(' (1).')
for thisfile in files:
matcherone = (lastfile[0:onepos] + lastfile[onepos+4:len(lastfile)])
if matcherone == thisfile:
lastfilesize = os.path.getsize(os.path.join(root,lastfile));
thisfilesize = os.path.getsize(os.path.join(root,thisfile));
if lastfilesize-thisfilesize == 0:
print "Deleting : ", os.path.join(root,lastfile);
os.remove(os.path.join(root,lastfile));