我有以下在 XP 上运行良好的脚本,因为我在 Windows 7 Professional 上有一台新 PC,代码已停止工作
import os
import shutil
from time import strftime
logsdir="c:\logs"
zipdir="c:\logs\puttylogs\zipped_logs"
zip_program="zip.exe"
for files in os.listdir(logsdir):
if files.endswith(".log"):
files1=files+"."+strftime("%Y-%m-%d")+".zip"
os.chdir(logsdir)
os.system(zip_program + " " + files1 +" "+ files)
shutil.move(files1, zipdir)
os.remove(files)
我得到的错误是 U:>python logs.py zip 警告:名称不匹配:ping_dms_155.log
zip error: Nothing to do! (ping_dms_155.log.2013-05-14.zip)
Traceback (most recent call last):
File "logs.py", line 24, in <module>
shutil.move(files1, zipdir)
File "c:\python27\lib\shutil.py", line 301, in move
copy2(src, real_dst)
File "c:\python27\lib\shutil.py", line 130, in copy2
copyfile(src, dst)
File "c:\python27\lib\shutil.py", line 82, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: 'ping_dms_155.log.2013-05-14.zip'
我想不出它为什么会停止工作,在此先感谢