Concerning my previous post, unfortunately listfolder does not recognize previous sorting. I know the help file mentions that it uses the system's native sorting. Any chance Don we could have a flag to the listfolder SC that would utilize the sort in the previous script line (e.g., sortby Accessed, d;)? It would make it much easier to utilize this information in a script.
Also, since I was looking to perform all the actions in the background (e.g., find the last accessed file in a folder that is not the "current" folder), my first point above was also not valid, in that, it works, but I usually saw the location change when performed in the script using that code or similar and that's obviously not what I wanted.
Sammay as much as I liked your amazing solution to find the last accessed file in a folder using runret and good old DOS dir, I was still curious to come up with a XY solution. This works below, 7 lines of code verses your one line. It may or may not be hard to believe since your one line has to run a command box, but the XY's 7 lines of code is significantly faster executing - about 10 times faster though even more so on subsequent runs - we're talking msec though so we probably wouldn't notice.
Code: Select all
$TBFileAge = "";
$TBs = listfolder("d:\tools\xyplorer\toolbars", "*.txt", 1, "|");
foreach ($TBfile, $TBs, "|", , "") {
$p = property("#5","$TBfile"); //accessed date
$Age = datediff("$p", , "n"); //difference in time between now and accessed date in minutes
$TBFileAge = $TBFileAge . $Age . "--" . $TBfile . "|"; }
$TB_last = getpathcomponent(gettoken(gettoken(formatlist($TBFileAge, ne, "|"), 1, "|"), 2, "--"), "base"); //weed out last accessed file
verses
Code: Select all
$TB_last = replace(gettoken(runret("cmd.exe /c dir $DIR_TOOLBARS /B /T:A /O:-D /A:-D"), 1, chr(13)),".txt", "");