I want to match the filename by passing a list of substrings to avoid some files in loop if the string matches with the filename. Here's my code:
list_of_files = glob.glob('D:/folder/*.gz') # create the list of file
mylist=['abcd11','abcd12','jklm12','wxyz.12']
for file_name in list_of_files:
for ind in df.index:
if df['filename'][ind] in file_name: #filename column contains full file names
for i in mylist:
if i not in file_name:
print(file_name)
The thing is, it is also returning filenames which are matching with those list items. following code is working if I pass only one substring in for loop, but I want to match multiple substrings to avoid multiple files.
list_of_files = glob.glob('D:/folder/*.gz') # create the list of file
for file_name in list_of_files:
for ind in df.index:
if df['filename'][ind] in file_name: #filename column contains full file names
if 'abcd11' not in file_name:
print(file_name)
What I have tried:
I tried with two way
###########################first
list_of_files = glob.glob('D:/folder/*.gz') # create the list of file
mylist=['abcd11','abcd12','jklm12','wxyz.12']
for file_name in list_of_files:
for ind in df.index:
if df['filename'][ind] in file_name: #filename column contains full file names
for i in mylist:
if i not in file_name:
print(file_name)
################second
list_of_files = glob.glob('D:/folder/*.gz') # create the list of file
mylist=['abcd11','abcd12','jklm12','wxyz.12']
for file_name in list_of_files:
for ind in df.index:
if df['filename'][ind] in file_name: #filename column contains full file names
is_in_list = False
for i in mylist:
if i in file_name:
is_in_list = True
if not is_in_list:
print(file_name)