Home > Enterprise >  Finding file based on user input?
Finding file based on user input?

Time:10-19

I printed files using os.listdir() and found the files inside the folder i am looking for. I'm now looking for user input to know which files to look in. The files are in years and month and I'm not sure how?

Picture of my code now

CodePudding user response:

Are you expecting a year and month as input from the user? In that case you could parse the input string, then use some kind of regex matching to find the corresponding file.

CodePudding user response:

Could try using this in that case:

year = input("Enter year :")
month = input("Enter day :")
date = year   month
found = False
for file_name in a:
    if date in file_name:
        print("File found!")
        found = True
        break
if not found:
    print("File not found")
  • Related