csv - filtered list of files in a directory -
i have files in directory following naming convention arriving daily , wish filter list of file interoperate data. have been playing regular , finding difficult match file want filter.
import re fnames = ["jeexport_20150501-20150531_credit-balance-adjustment-applied_20150531183249.csv", "jeexport_20150501-20150531_external-credit-balance-payment_20150531183254.csv", "jeexport_20150501-20150531_external-payment_20150531183251.csv", "jeexport_20150501-20150531_invoice-item_20150531183255.csv", "jeexport_20150501-20150531_invoice-item-adjustment_20150531183304.csv" "jeexport_20150501-20150531_invoice-item-adjustment-tax_20150531183313.csv", "jeexport_20150501-20150531_taxation-item_20150531183240.csv"] element in fnames: m = re.match("[a-za-z]+\-[a-za-z]+|-[a-za-z]+", element) if m == 'invoice-item-adjustment': print(element) #
i don't think need regex. work?
fnames = ["jeexport_20150501-20150531_credit-balance-adjustment-applied_20150531183249.csv", "jeexport_20150501-20150531_external-credit-balance-payment_20150531183254.csv", "jeexport_20150501-20150531_external-payment_20150531183251.csv", "jeexport_20150501-20150531_invoice-item_20150531183255.csv", "jeexport_20150501-20150531_invoice-item-adjustment_20150531183304.csv", "jeexport_20150501-20150531_invoice-item-adjustment-tax_20150531183313.csv", "jeexport_20150501-20150531_taxation-item_20150531183240.csv"] element in fnames: if 'invoice-item-adjustment' in element: print(element) # jeexport_20150501-20150531_invoice-item-adjustment_20150531183304.csv jeexport_20150501-20150531_invoice-item-adjustment-tax_20150531183313.csv
Comments
Post a Comment