944,030 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 8655
  • Python RSS
Apr 12th, 2007
0

how to copy a file

Expand 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pinder is offline Offline
5 posts
since Mar 2007
Apr 12th, 2007
0

Re: how to copy a file

Create a list of file names that match your criteria:
Python Syntax (Toggle Plain Text)
  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)]
Reputation Points: 86
Solved Threads: 40
Junior Poster
solsteel is offline Offline
141 posts
since Mar 2007
Apr 13th, 2007
0

Re: how to copy a file

Click to Expand / Collapse  Quote originally posted by pinder ...
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
Python Syntax (Toggle Plain Text)
  1. import shutil,glob,os
  2. os.chdir("wherefileis")
  3. for FILE in glob.glob("journal*"):
  4. shutil.copy(FILE, "someotherdir")
Reputation Points: 75
Solved Threads: 44
Junior Poster
ghostdog74 is offline Offline
156 posts
since Apr 2006
Apr 13th, 2007
0

Re: how to copy a file

thx alot for ur help guys
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pinder is offline Offline
5 posts
since Mar 2007
Dec 29th, 2008
0

Re: how to copy a file

print 1 to 10 numbers using c
Reputation Points: 7
Solved Threads: 0
Newbie Poster
nrupparikh is offline Offline
5 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Programmatically Select item in TreeCtrl
Next Thread in Python Forum Timeline: prime no





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC