I am using Python 3 and want to check for 2 things. Firstly I want to ensure there are 3 files in a directory, then I want to check that the 3 files match certain rules....
- 3 files in directory
- A file called testfile1.txt
- A file that matches myfile-*.txt (for example myfile-473spain.txt)
- A file that matches newlog-*.log (for example newlog-55.log)
I have this so far...
list = os.listdir('myfiles') # dir is your directory path
number_files = len(list)
if number_files !=3 :
print('Incorrect Number Of Files')
else:
print('Correct Number Of Files')
if os.path.isfile('myfiles/testfile1.txt'):
print ("myfiles/testfile1.txt - FOUND")
else:
print ("myfiles/testfile1.txt - NOT FOUND")
But I am now stuck on how to search for the 2 partial match files. What can I try next?