Question Locked

Using Python how can i move files

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am new to python and I want to write a program which would transfer files under one folder
structure (there are sub folders) to single folder. Can anyone give me some idea like which library files or commands would be suitable for this file transfer task.

Thanks

2 replies

by lkk2116

Hi this is the code which I wrote till now. I t giving permission denied error for sub folders of source directory. Does anyone have any idea what is going wrong

import os
import shutil
def copytreetosinglefolder(src, dst):
names = os.listdir(src)
if (os.path.isdir(dst)==False):
os.mkdir(dst)
for name in names:
srcname = os.path.join(src, name)
try:
shutil.copy2(srcname, dst)
except (IOError, os.error), why:
print "Can't copy %s to %s: %s" % (`srcname`, `dst`, str(why))

copytreetosinglefolder('c:\\src','d:\\dest')

This discussion is closed to new replies.