문제

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.

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top