我試圖散裝在一個目錄重命名文件給「錯誤2」
if len(self.toLoc.get()) == 0:
searchRev = "_R" + newRev
for filename in os.listdir(App.pdfDir):
sep = searchesri
rest = filename.split(sep, 1)[0] + searchRev
os.rename(filename, rest)
else:
searchRev = "_R" + newRev + fromLocation + toLocation
print searchRev
重命名一些PDF時,我運行它,它給我的錯誤
File "F:\TOOLS\PythonTools\VCR.py", line 411, in renameMaps
os.rename(filename, rest)
WindowsError: [Error 2] The system cannot find the file specified
我可以打印文件名在for循環中,並通過...
我認爲你需要提供完整路徑的文件。 – hjpotter92
'os.path.join'是你的朋友。 – msvalkon