2012-07-02 113 views
2

IM巡航能力一个非常简单的代码,但由于某种原因,我得到错误没有2 这里是代码:IO错误:[错误2]没有这样的文件或目录shutil

import os, shutil 

src=r"C:/Documents and Settings/user/Desktop/FilesPy" 
des=r"C:/Documents and Settings/user/Desktop/tryPy/Output" 
srcFile=r"C:/Documents and Settings/user/Desktop/tryPy/Input/FilesToCopy.txt" 

srcFile=open(srcFile,'a+') 

for line in srcFile: 
    name=line.rstrip() 
    pathS=os.path.join(src,name) 
    pathD=os.path.join(des,name) 
    if os.path.exists(pathS): 
     shutil.copy(pathS,des) 

    else: 
     print 'false' + path 

,但我得到的是:

IOError: [Errno 2] No such file or directory: 'C:/Documents and Settings/user/Desktop/tryPy/Output\\blatwo.docx' 

我真的不知道该怎么办尝试reasearching整个网络没有得到答案,请帮助我。

谢谢:)

编辑: 这里是日食运行的完整的跟踪:

pydev debugger 
Traceback (most recent call last): 
    File "D:\EasyEclipse-for-Python-1.3.1\plugins\org.python.pydev.debug_1.3.13\pysrc\pydevd.py", line 803, in <module> 
    debugger.run(setup['file'], None, None) 
    File "D:\EasyEclipse-for-Python-1.3.1\plugins\org.python.pydev.debug_1.3.13\pysrc\pydevd.py", line 655, in run 
    execfile(file, globals, locals) #execute the script 
    File "D:\Python\CopyChosenFiles\Copy of CopyFiles.py", line 16, in <module> 
    shutil.copy2(pathS,pathD) 
    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, 'rb') as fdst: 
IOError: [Errno 2] No such file or directory: 'C:/Documents and Settings/user/Desktop/tryPy/Output\\blatwo.docx' 
Exception AttributeError: "'NoneType' object has no attribute 'print_exc'" in <function _remove at 0x00AC52B0> ignored 
+0

@Levon在那里我编辑它,并添加了正确的代码.. – DrDark

+3

什么行?你可以发布完整的追溯? – mgilson

+0

嗯,我试过这已经是多数民众赞成为什么我把路径D,并把des insted = \仍然是相同的错误.. – DrDark

回答

2

本替换变量赋值:

src = os.path.join('C:', 'Documents and Settings', 'user', 'Desktop', 'FilesPy') 
des = os.path.join('C:', 'Documents and Settings', 'user', 'Desktop', 'tryPy', 'Output') 
srcFile = os.path.join('C:', 'Documents and Settings', 'user', 'Desktop', 'tryPy', 'Input', 'FilesToCopy.txt') 

或者,在路径中使用反斜杠,因为您使用的是windows ...

src = r"C:\Documents and Settings\user\Desktop\FilesPy" 
des = r"C:\Documents and Settings\user\Desktop\tryPy\Output" 
srcFile = r"C:\Documents and Settings\user\Desktop\tryPy\Input\FilesToCopy.txt" 
相关问题