Skip to content

Instantly share code, notes, and snippets.

@ibelgin
Last active October 6, 2020 08:24
Show Gist options
  • Save ibelgin/d73be73c4189729f43500859a7acc1e5 to your computer and use it in GitHub Desktop.
Save ibelgin/d73be73c4189729f43500859a7acc1e5 to your computer and use it in GitHub Desktop.
# We have seen how to search for a particular file extension and also how to get files modified within a
# date range. For assignment, you need to combine both. User should
# be able to search for python files modified in a date range
import os
import datetime
def file_extension_finder(pat,start_date,end_date):
file_extension = input("Enter The File Extension's -> ")
for (root,directory,files) in os.walk(pat.strip()):
for file in files:
if file.endswith(file_extension):
x = get_modified_date(file)
if x >= start_date and x <= end_date:
print(file)
def get_modified_date(file):
return datetime.date.fromtimestamp(os.path.getmtime(file))
def get_date():
start_date1 = input("Enter Start Date in Format ( YYYY-MM-DD ) -> ")
end_date1 = input("Enter End Date in Format ( YYYY-MM-DD ) -> ")
year_start, month_start, day_start = map(int , start_date1.split('-'))
year_end, month_end, day_end = map(int , end_date1.split('-'))
start_date = datetime.date(year_start,month_start,day_start)
end_date = datetime.date(year_end,month_end,day_end)
pat = input("Enter The Path -> ")
file_extension_finder(pat,start_date,end_date)
get_date()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment