0

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

4
Contributors
4
Replies
6
Views
11 Years
Discussion Span
Last Post by nrupparikh
0

Create a list of file names that match your criteria:

import os

path_name = 'your_directory'
key = 'journal'

nameList = [os.path.join(path_name, n) for n in os.listdir(path_name) \
            if os.path.isfile(os.path.join(path_name, n)) and n.startswith(key)]
0

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

import shutil,glob,os
os.chdir("wherefileis")
for FILE in glob.glob("journal*"):
     shutil.copy(FILE, "someotherdir")
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.