i am writing a python script to extract only the files that I want to read in a folder. I defined the places of characters in file names first. Then try to call them by a def(). The example filenames are like: '_4111_12.dat' or
'_4111_5.dat' or
'**_8322_5.dat
The script below shows me still all the files in the folder. How can I specify the file names exactly and call and add them to a list? Thanks in advance.
The code is:
def plot(folder_path, xx= str(41), zz=str(11), a=str(12)):
usefiles=[]
for filepath in glob.iglob(folder_path):
mod = filepath[5:7] #define mod characters in file name
station= filepath[8:10] #define stations characters
iter1 = filepath[11] # place of the iteration number if value between 1-9.
iter2 = filepath[11:13] #place of the iteration number when it is between 10-30
if mod== xx:
if station == zz:
if len(a) == 1:
iter1= a
else:
iter2=a
usefiles.append(filepath)
Aucun commentaire:
Enregistrer un commentaire