我已經做了Python程序,將清理目前的不必要的名字在我下載的種子文件+文件夾,這樣我就可以把它上傳到我的無限Google雲端硬盤存儲帳戶沒有太多麻煩。WindowsError:[錯誤2]系統找不到指定的文件,也不能在Python
然而,它給我的:WindowsError: [Error 2] The system cannot find the file specified
一定數量的迭代之後。 如果我再次運行程序,它在某些迭代中可以正常工作,然後彈出相同的錯誤。
請注意,我已採取預防措施,使用os.path.join
來避免此錯誤,但它不斷出現。由於這個錯誤,我必須在選定的文件夾/驅動器上運行數十次程序。
這裏是我的程序:
import os
terms = ("-LOL[ettv]" #Other terms removed
)
#print terms[0]
p = "E:\TV Series"
for (path,dir,files) in os.walk(p):
for name in terms:
for i in files:
if name in i:
print i
fn,_,sn = i.rpartition(name)
os.rename(os.path.join(path, i), os.path.join(path, fn+sn))
for i in dir:
if name in i:
print i
fn,_,sn = i.rpartition(name)
os.rename(os.path.join(path, i), os.path.join(path, fn+sn))
和錯誤回溯:
Traceback (most recent call last):
File "E:\abcd.py", line 22, in <module>
os.rename(os.path.join(path, i), os.path.join(path, fn+sn))
WindowsError: [Error 2] The system cannot find the file specified
是的!這是我期望的答案。在猜測問題(這是一個艱難的部分)之後,我已經在一小時前解決了它,解決方案並沒有花費太多時間,我所做的只是使用'enumerate'並編輯'dir'重命名目錄的索引。 –
順便說一句,在我猜錯了之後,我在[這裏]發佈了另一個問題(http://stackoverflow.com/questions/35683291/how-to-update-current-directories-in-the-list-of -os-walk-while-renaming-it-in-re),在那裏我用一個答案更新帖子。 –