This may be a very easy concept, but I’m just not able to figure it out. If I have more than one log file in a folder, how could I use relevance to return the filename of just the most recently modified log? Let’s say my files are called:
20090508.log
20090509.log
20090510.log
Here’s what I have so far, but cannot get my syntax correct:
(modification time of it as string) of file whose (name of it ends with “.log” AND (first 8 of last 12 of it = (maximum of (it as integer) of firsts 8 of lasts 12 of names whose (exists (firsts 8 of lasts 12 of it) as string as integer)) of files) of folder “C:\temp”
I should have used my reallife example instead of Log files. We have a utility that is running and creating an output file. We keep up to 3 most recent files. I want to know when the most recent file is modified so we will always know the most recent time the utility has run. It may not always e daily, so we may not have one from yesterday.
How could we look at 3 files in a folder and see which is the newest?
Thanks for that. I actually tried playing around with something like that last night, but couldn’t get the syntax correct. Please tell me what I’m doing wrong with the following:
modification time of file whose (preceding texts of firsts “.log” of it as integer = maximum of (preceding texts of firsts “.log” of it as integer) of names of files of it) of folder “C:\temp”
You could get a little more elegant than this, but I think it will do the job and should be decently efficient unless there are tons of files in that folder.
modification times of items 1 of (maximum of (it as integer) of preceding texts whose (exists it as integer) of firsts “.log” of names of files of it, files of it) whose (item 0 of it = preceding text of first “.log” of name of item 1 of it as integer) of folder “C:\Temp”
I have been trying to figure out the correct syntax to find the newest file in a folder using tuples for quite a while and was never able to get it.
I have generalized this answer to work with any file based upon modification time:
(name of it, modification time of it) of items 1 of (maximum of modification times of files whose(name of it as lowercase ends with “.log”) of it, files whose(name of it as lowercase ends with “.log” of it) of it) whose (item 0 of it = modification time of item 1 of it) of folder “C:\Temp”
I was trying to figure out how to grab the latest log file in a directory, but not just have the name of the file, but the file object itself, so that I could do further analysis by looking into the file’s contents.
This is what I came up with:
file whose (name of it contains “.log” AND (creation time of it = maximum of creation times of files of parent folder of it)) of folder “C:\Log\Folder\Path”
This could cause an issue in the unlikely event of two files of exact same creation times. You could also swap creation times for modification times, depending on need.