为什么我在cmd中得到IOError invalid mode('wb')或filename而不是PowerShell?

2024-05-14 10:40:12 发布

您现在位置:Python中文网/ 问答频道 /正文

当我以admin的身份在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"'

脚本非常简单:

^{pr2}$

Tags: 文件inpy脚本lib错误linefile
1条回答
网友
1楼 · 发布于 2024-05-14 10:40:12

您需要在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)

相关问题 更多 >

    热门问题