Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding the last-modified of a file

Status
Not open for further replies.

math

Programmer
Mar 21, 2001
56
0
0
BE
Hi,
I want to be able to sort a set of files(images) by there last-modified property... I have a webcam and it takes 10 different pics each hour... I want to be able to sort those images. the oldest first and the newest last... All I need is a command to retreave that property, so if the filename is in $file, how do i get it??

i need preferably a time in seconds, so that it's easy to compare the times...

Thanks in advance,
math
 
[tt]sort {(-M $a) <=> (-M $b)} @files[/tt]
should work!
 
Can someone please explain what the -M does? (for the future) and what the $a and $b stand for?

What would be the code to sort if all the filenames are in @files?

Thanks so much...

math
 
'-M' is a unary file test operator that returns the modification time of a file. there are lots of different file test operators.
the $a and $b have to do with the sort function. if you provide it with a block before the array to be sorted, it uses the block to compare the elements, locally setting $a and $b to be arbitrary values in the array. the block must then reaturn a 1, 0, or -1, depending on their relation, and how you want that relation to sort the array. <=> returns those numbers based on a numeric comparison, in this case, performed on the modification times of the files in the array.
the code to sort if all the files are in @files is what was already up there, only with a :[tt]
@sorted = ...[/tt]

in front of it.
HTH &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top