"most recent" relevance

(imported topic written by jeko1791)

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”

(imported comment written by BenKus)

Hey jeko,

Actually, this is one of the examples in our Fixlet Development (202) course:

This relevance will return the log file name from yesterday:

(((year of it) as string & month of it as two digits & ((day_of_month of it as two digits) as string)) of (current date - 1 * day)) & “.log”

Ben

(imported comment written by jeko1791)

Thanks Ben.

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?

(imported comment written by jessewk)

You can try something like this:

maximum of (preceding texts of firsts “.log” of it as integer) of names of files of folder “c:\temp”

(imported comment written by jeko1791)

jessewk,

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”

(imported comment written by jessewk)

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”

(imported comment written by jgstew)

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”

(imported comment written by jeko1791)

That worked perfectly, thanks jessewk!

(imported comment written by khanand91)

hi, i was wondering whether there is a simple way to cast a folder name to integer and return the gratest value?

q:names of folders of folder “C:\WINNT\Microsoft.NET\Framework”

a:v1.0.3705

v1.1.4322

v2.0.50727

v3.0

v3.5

I get singular expression error with the follow test:-

maximum of (following texts of firsts “v” of it as integer) of names of folders of folder “C:\WINNT\Microsoft.NET\Framework”

thanks

(imported comment written by jgstew)

Here is an alternative:
http://bigfix.me/relevance/details/2998365

(
(maximum
of
(
it

as
version)
of
names
of
keys
whose
(name
of

it

as
lowercase
starts

with

“v”
)
of
key
"HKLM\Software\Microsoft\NET Framework Setup\NDP"

of
native registry)
)

Related:

http://bigfix.me/relevance/details/1319

http://bigfix.me/analysis/details/2994589

(imported comment written by NoahSalzman)

How about:

maximum of ((names of folders of folder "C:\WINNT\Microsoft.NET\Framework") as version)

(imported comment written by khanand91)

hi noah,

thanks for the reply - that seems to do the trick. I didnt think that a folder name could be cast as version like that?

(imported comment written by SystemAdmin)

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.