how to copy a file

Reply

Join Date: Mar 2007
Posts: 5
Reputation: pinder is an unknown quantity at this point 
Solved Threads: 0
pinder pinder is offline Offline
Newbie Poster

how to copy a file

 
0
  #1
Apr 12th, 2007
Hi,
I'm trying to copy a file in python, I have imported the shutil module
My problem is that I want to copy file in a directory beginning with a certain name. Example I have 5 file in the fodler but i want to copy all the one tat begin with journal.something How could i do that

thanks
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 110
Reputation: solsteel is on a distinguished road 
Solved Threads: 31
solsteel solsteel is offline Offline
Junior Poster

Re: how to copy a file

 
0
  #2
Apr 12th, 2007
Create a list of file names that match your criteria:
  1. import os
  2.  
  3. path_name = 'your_directory'
  4. key = 'journal'
  5.  
  6. nameList = [os.path.join(path_name, n) for n in os.listdir(path_name) \
  7. if os.path.isfile(os.path.join(path_name, n)) and n.startswith(key)]
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 148
Reputation: ghostdog74 is on a distinguished road 
Solved Threads: 40
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: how to copy a file

 
0
  #3
Apr 13th, 2007
Originally Posted by pinder View Post
Hi,
I'm trying to copy a file in python, I have imported the shutil module
My problem is that I want to copy file in a directory beginning with a certain name. Example I have 5 file in the fodler but i want to copy all the one tat begin with journal.something How could i do that

thanks
  1. import shutil,glob,os
  2. os.chdir("wherefileis")
  3. for FILE in glob.glob("journal*"):
  4. shutil.copy(FILE, "someotherdir")
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 5
Reputation: pinder is an unknown quantity at this point 
Solved Threads: 0
pinder pinder is offline Offline
Newbie Poster

Re: how to copy a file

 
0
  #4
Apr 13th, 2007
thx alot for ur help guys
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 5
Reputation: nrupparikh is an unknown quantity at this point 
Solved Threads: 0
nrupparikh nrupparikh is offline Offline
Newbie Poster

Re: how to copy a file

 
0
  #5
Dec 29th, 2008
print 1 to 10 numbers using c
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC