shutil.move IOError: [Errno 2] - When in loop [closed]

纵然是瞬间 提交于 2019-12-11 02:56:41

问题


If I run shutil.move(file, dest) on its own it works fine, the problem I'm having is when I loop through, the loop works fine without the shutil.move.

IOError: [Errno 2] No such file or directory: 'test.txt'

path = '/media/usb/Test/'
dest = '/media/usb/Done/'

for file in os.listdir(path):
    fullpath = os.path.join(path, file)
    f = open( fullpath , 'r')
    dataname = f.name
    print dataname

    shutil.copy(file, dest)

I know that this is something simple and I've tried a number of different things but just can't get my head around this.


回答1:


You are giving shutil.copy the filename (file), and not the full path, so it can find the file.

Maybe you meant :

shutil.copy(fullpath, dest)


来源:https://stackoverflow.com/questions/13193015/shutil-move-ioerror-errno-2-when-in-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!