APRES Posted November 15, 2006 Posted November 15, 2006 The question looks simple, but I couldn't sort it out quickly, also via search. How do I get the name of the "youngest" file in a directory? (Directory may have 1000s of files so if there is solution without looping all files it would be better) Thank you.
xcal Posted November 15, 2006 Posted November 15, 2006 The question looks simple, but I couldn't sort it out quickly, also via search. How do I get the name of the "youngest" file in a directory? (Directory may have 1000s of files so if there is solution without looping all files it would be better) Thank you. I wanted to solve it for kicks, so here's what I did: #include <Array.au3> Dim $array[1] = [0] $dir = 'c:\' $start = FileFindFirstFile($dir & '*.*') While 1 $file_found = FileFindNextFile($start) If @error Then ExitLoop $time = FileGetTime($dir & $file_found, 1, 1) _ArrayAdd($array, $time & '|' & $file_found) WEnd _ArraySort($array) $array[0] = UBound($array) - 1 ;yes yes I know, but I like 0 to = total _ArrayDisplay($array, 'with date/time (YYYYMMDDHHMMSS)') For $i = 1 To $array[0] $file_only = StringSplit($array[$i], '|') $array[$i] = $file_only[2] Next _ArrayDisplay($array, 'without date/time') I don't think you could actually do it without a loop? How To Ask Questions The Smart Way
/dev/null Posted November 15, 2006 Posted November 15, 2006 The question looks simple, but I couldn't sort it out quickly, also via search.How do I get the name of the "youngest" file in a directory?(Directory may have 1000s of files so if there is solution without looping all files it would be better) Thank you.Run() with "dir /od". Then parse the output. The last line contains the "youngest" file.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
APRES Posted November 15, 2006 Author Posted November 15, 2006 Run() with "dir /od". Then parse the output. The last line contains the "youngest" file.CheersKurtThank xcal ! Very good generic script.I guess the solution of Kurt is in my situation better.
Confuzzled Posted November 19, 2006 Posted November 19, 2006 dir /o-d and parse the first file name may be quicker.
/dev/null Posted November 19, 2006 Posted November 19, 2006 dir /o-d and parse the first file name may be quicker. In general you are right, but the time difference would not be very big, something around 0.05 sec... CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now