python - Using a reference list to find specific files by name -


i have list of file names extracted csv stored in variable, want search within directory, see extraction of list variable names filenames below. if found want perform operation on matched files 1 one.

#python 3.5, pandas 0.17.1 #reading in list characteristics of files index = pd.read_csv('index.csv',usecols = ['filenumber','province']) #automating extraction of column filename on basis of province , full rows province = index[index.province == 'mg'] filenames = province['filenumber'] 

so far have not found solution problem. new python , therefore appreciate push in right direction in form of solution or reference material read on these types of operations.

in summary:

with variable filenames has names of files (minus file type (.csv)), want find files these names in 1 directory/folder. , after (or during search files) perform operation on each file.

is looking for?

import os  filenames =['testfile1','testfile2']  file in filenames:     if os.path.isfile(file+'.csv'):         print "file "+ file + ".csv exists."     else:         print "file "+ file + ".csv not exist." 

edit: following python 3.x (untested, since have none):

import os  filenames =['testfile1.csv','testfile2.csv']  file in filenames:     if os.path.isfile(file):         print("file exists.")     else:         print("file not exist.") 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -