当我在cmd中运行此脚本时(作为管理员),我收到此错误。当我在PowerShell中针对同一组文件运行相同的脚本时,它可以正常工作而没有错误。它失败的文件没有非法字符。
C:\Windows\system32>python D:\Syncback\OurDocs\Darrick\MyPrograms\dbhf.py "C:\Us
ers\Darrick\Dropbox\Camera Uploads" "F:\Pictures\AndroidPics\Auto\"
looking for old files...
2015-06-05 15.33.18.jpg
moving C:\Users\Darrick\Dropbox\Camera Uploads\2015-06-05 15.33.18.jpg
Traceback (most recent call last):
File "D:\Syncback\OurDocs\Darrick\MyPrograms\dbhf.py", line 29, in <module>
shutil.move(filepath, destPath)
File "C:\Python27\lib\shutil.py", line 299, in move
copy2(src, real_dst)
File "C:\Python27\lib\shutil.py", line 128, in copy2
copyfile(src, dst)
File "C:\Python27\lib\shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 22] invalid mode ('wb') or filename: 'F:\\Pictures\\AndroidPics\
\Auto"'
脚本非常简单:
dropboxPath = sys.argv[1]
destPath = sys.argv[2]
while True:
bufferTime = time.time() - 6000
files = [(f) for f in os.listdir(dropboxPath) for t in filetypes if t in f]
print 'looking for old files...'
for fn in files:
print fn
filepath = dropboxPath+"\\"+fn
if os.path.isfile(filepath):
if os.stat(filepath).st_mtime < bufferTime:
print "moving "+filepath
shutil.move(filepath, destPath)
print "...Going to sleep for 100 minutes now"
time.sleep(6000)
答案 0 :(得分:0)
您需要在destPath
import os.path
dropboxPath = sys.argv[1]
destPath = sys.argv[2]
while True:
bufferTime = time.time() - 6000
files = [(f) for f in os.listdir(dropboxPath) for t in filetypes if t in f]
print 'looking for old files...'
for fn in files:
print fn
filepath = dropboxPath+"\\"+fn
if os.path.isfile(filepath):
if os.stat(filepath).st_mtime < bufferTime:
print "moving "+filepath
shutil.move(filepath, destPath + fn)
print "...Going to sleep for 100 minutes now"
time.sleep(6000)