I am trying to find the file with the largest number in the filename in each subdirectory. This is so I can acomplish opening the most recent file in each subdirectory. Each file will follow the naming convetion of date filename.xlsx.
Ex. 20180620 file name.xlsx
I have a code that works for searching one directory for largest numbers.
dirname = py.path.local(path)list_of_files = []for file in dirname.visit(fil='*.xlsx', bf=True):list_of_files.append(file)largest = max(list_of_files)
print (largest)
I am pretty new to Python and I can't quite figure out how to make this style of code work looking for the file with the largest number in each subdirectory within a directory. I have tried many variations off of this following code, but I can't get it to print out just the file with the largest number from each subdirectory.
list_of_files = []for root, dirs, files in os.walk(path):for name in files:if name.endswith((".xlsx")):list_of_files.append(files)largest = max(list_of_files)print (largest)
Any help would be greatly appreciated!