Copy files from different source to a single folder?

A forum for general discussion of the Python programming language.

Copy files from different source to a single folder?

Postby eakDev » Sat Mar 09, 2013 12:58 pm

Hi guys,

Ok I have been playing with how to copy in python with the following:
copyfile - only works when source and destination are both file
copy - can copy to a directory but i am getting an IOError: Permission Denied
copytree - does not work when destination folder exist

All i want is to copy several files from different directories into a single folder. Help please.
eakDev
 
Posts: 3
Joined: Sat Mar 09, 2013 12:45 pm

Re: Copy files from different source to a single folder?

Postby micseydel » Sat Mar 09, 2013 7:54 pm

Please provide your full code that reproduces the problem, and the full traceback for any code that you get an error when you run. I suspect that the second version you list here is the one that will end up working but requires a fix of some kind.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 939
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Copy files from different source to a single folder?

Postby Ephexeve » Mon Mar 11, 2013 10:38 am

eakDev wrote:Hi guys,

Ok I have been playing with how to copy in python with the following:
copyfile - only works when source and destination are both file
copy - can copy to a directory but i am getting an IOError: Permission Denied
copytree - does not work when destination folder exist

All i want is to copy several files from different directories into a single folder. Help please.


You can easily do that with shutil.

Code: Select all
files = os.listdir(".")
for f in files:
    shutil.copy(f, dest_folter)
- Ephexeve

Python/Ruby/C
Vim/Gentoo
Mysql/PostgreSQL/MongoDB
Ephexeve
 
Posts: 13
Joined: Thu Feb 07, 2013 4:13 pm
Location: Brazil


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest