copying files through Python
Tim Chase
python.list at tim.thechases.com
Wed Feb 13 17:13:39 EST 2008
> I am new to python. Infact started yesterday and feeling out of place.
> I need 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. I am sure its matter of few commands. It
> would be even more great if I could get some sample code with
The shutils.copytree() command[1] will do what you describe
Depending on your source, and if you want to make the dest
writeable (such as copying off a CD), you may also need to use
os.walk() [2] combined with os.chmod(filepath, stat.S_IWRITE) [3]
-tkc
[1]
http://docs.python.org/lib/module-shutil.html#l2h-2297
[2]
http://docs.python.org/lib/os-file-dir.html#l2h-2707
[3]
http://docs.python.org/lib/os-file-dir.html#l2h-2677
More information about the Python-list
mailing list