![](/img/trans.png)
[英]using popen shows WindowsError: [Error 2] The system cannot find the file specified
[英]why windows shows The system cannot find the file specified?
由於我是phython的新生嬰兒,所以找不到問題。這是我的代碼。
import os
def rename_files():
#get the all files in the directory
file_list = os.listdir(r'C:\Users\squalporeover\Desktop\prank')
print ( file_list )
#rename each file
for file_name in file_list:
os.rename(file_name,file_name.translate(None,'0123456789'))
rename_files()
file_list
僅包含文件名,而不是完整路徑。 您需要將路徑名傳遞給os.rename。
path = r'C:\Users\squalporeover\Desktop\prank'
file_list = os.listdir(path)
for file_name in file_list:
full_path = os.path.join(path, file_name)
os.rename(full_path, file_name.translate(None,'0123456789'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.