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

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)]

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")

thx alot for ur help guys