×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

finding the last-modified of a file

finding the last-modified of a file

finding the last-modified of a file

(OP)
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

RE: finding the last-modified of a file

sort {(-M $a) <=> (-M $b)} @files
should work!

RE: finding the last-modified of a file

(OP)
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

RE: finding the last-modified of a file

'-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 :
@sorted = ...

in front of it.
HTH

"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close