How would you get the 10 most recent files in a folder?
It is much easier to get the first 10 items than it is to get the last 10 using relevance.
How would you get the 10 most recent files in a folder?
It is much easier to get the first 10 items than it is to get the last 10 using relevance.
It’s horribly inefficient but maybe you could do 10 nested parens where each time you identify the most recent file and exclude that file from the next “most recent file” also building the result list as you go.
I have thought of that, but that doesn’t scale well and is basically the worst case option, and often extremely slow.
I do have relevance to get the last X lines of a file, which is very useful.
jgstew,
If it’s in an action script, I would throw the list in a file and take the last 10 lines out of it and delete the file. Seems awkward and inefficient, but it does work.
Shame there are no list sorting/indexing inspectors (for a reason, supposedly).
However, I would be interested to know how you get the first 10 entries of a list, as I do think I have a way of getting the answer, but it depends how your process works.
First X of anything that can be represented by a string:
tuple string items (0;1;2;3;4;5;6;7;8;9) of "Item1, Item2, Item3, ItemN"
Last X lines of a file:
Didn’t think about the tuple string…fairly clean but doesn’t scale fantastically well, but reasonable enough.
Anyway, give this a shot:
(I decided to pull files from system32 as there are quite a few and helps to see how it coped with amount.)
substrings separated by "|" of concatenation of characters (lengths of (following texts of (positions of it))) of concatenation "|" of tuple string items (0;1;2;3;4;5;6;7;8;9) of concatenation ", " of substrings separated by "|" of concatenation of characters (lengths of (following texts of (positions of it))) of (concatenation "|" of names of files whose (name of it ends with ".dll" and name of it starts with "b") of folder "C:\windows\system32")
A: bitsprx3.dll
A: bitsprx4.dll
A: bitsprx5.dll
A: bitsprx6.dll
A: bitsprx7.dll
A: biwinrt.dll
A: blackbox.dll
A: browcli.dll
A: browseui.dll
A: btpanui.dll
T: 165.164 ms
I: plural substring
Essentially, it puts the list of filenames into a string and reverses the whole string, strips off the tuple string elements you want and then reverses the list string again and returns the list items, which will be the last files in the folder.
Obviously, you will want to check numbers and if <= to what you want, you just take the files as is.
(Love it when a plan comes together)
Great solution but you have come across the main reason the client doesn’t have sort options either though having a “reverse” type of iterator would be potentially possible.
The client would have to keep everything in memory to sort it and that can be a lot…
Alanm
Well, but of course
Which is why we showed a solution to get around the issue, but hopefully it’s only used in reasonable cases…such as putting a limit filter in place to check for more than X files in the list and return the error.
It would be great if there was a built in way to get the first X or last X of a plural result. It would also be interesting if each item in a plural result was aware of it’s own position within the result set.
The issue is that without easy ways to do this, it often involves cobbling together inefficient relevance to make it work.
If I read this correctly, this relevance actually returns a limited set of filenames, based upon the alphabetical sort order of the filenames. I don’t see that this takes into account he modification time of the files as in the original request?
I think that in order to handle that, we’d have to also concatenate the file’s modification time with the filename, sort it, find the most recent X of them, them split off the modification time to get back to just the filename.
Of course you’ll have to manipulate the modification time into a sortable string, which is horrible enough; others “Sun 1 May” sorts after “Mon 2 May”, so you have to convert the time into a something like YYYYMMDDHHMMSS. The operation for doing that is pretty horrible on its own.