I need to use python to extract the date from filenames. The date is in the following format:
month-day-year.somefileextension
Examples:
**This is simple method to find date from text file in python**
import os
import re
file='rain.txt' #name of the file
if(os.path.isfile(file)): #cheak if file exists or not
with open(file,'r') as i:
for j in i: #we will travarse line by line in file
try:
match=re.search(r'\d{2}-\d{2}-\d{4}',j) #regular expression for date
print(match.group()) #print date if match is found
except AttributeError:
pass
else:
print("file does not exist")