Re: Shell script help - get date of last modified file in hierarchy
Re: Shell script help - get date of last modified file in hierarchy
- Subject: Re: Shell script help - get date of last modified file in hierarchy
- From: Mark Walsh <email@hidden>
- Date: Tue, 27 Mar 2007 19:10:16 -0400
Thanks for all the responses!
On 3/26/07 10:52 PM, "Mark J. Reed" <email@hidden> wrote:
> This works OMM:
>
> do shell script "perl -MFile::Find -MFile::stat -le 'my $latest_mtime
> = 0; find ( sub { my $mtime = stat($_)->mtime; $latest_mtime = $mtime
> if $mtime > $latest_mtime; }, @ARGV); print $latest_mtime;' " &
> quoted form of POSIX path of startFolder
>
> It returns the time_t value (seconds since 1970). if you want the
> date in a friendlier format, you can as usual use POSIX::strftime to
> get it:
>
> do shell script "perl -MFile::Find -MFile::stat -MPOSIX -le 'my
> $latest_mtime = 0; find ( sub { my $mtime = stat($_)->mtime;
> $latest_mtime = $mtime if $mtime > $latest_mtime; }, @ARGV); print
> strftime(\"%F %T\", localtime($latest_mtime));' " & quoted form of
> POSIX path of startFolder
That seems to do the trick. Thanks a lot! The first one might be slightly
faster, although the result not as human readable. For my purposes, though,
I just need the date for comparison, so it doesn't really matter if it's in
a date format, seconds since Elvis' birthday, or fortnights. I'm going to
run the same script on both folders, so as long as they both give me the
same result, I'm happy.
>> set mostRecentFile to (item 1 of (sort (files of entire contents of
>> folderRef) by modification date)) as alias
>
> Well, there you go. Finder *does* have a "newest file" field.
> Sort of. :)
>
> Thanks, Luther!
I'll check that, but I'm a little wary of using the 'entire contents', for
speed issues. Some of the folders I'll be checking will be pretty large (the
largest is around 30 gigs, with probably 1000-2000 files or so, in a couple
dozen subfolders), so I was hoping to steer away from anything that requires
an applescript loop or the finder's 'Entire contents' command. Plus, I'll be
running it twice, once across the network.
When I get a chance, I'll try all of the suggestions on one of the larger
job folders I have and see how well they work for me.
In case you're interested in the reasons I need this, this is all for a
script to cover myself after a problem with our server/IT guy last week. A
very large job I had worked on months ago was missing files on our server,
and although I was certain that they had been there, our IT guy's only
comment (which he repeated over and over again) was that if they weren't on
his backups, they couldn't have ever been on the server in the first place.
(he later found them on his backup tapes). So I now am using the 'Find'
command to log all of the filepaths on the server each day the jobs get
filed, and I wanted to add a little extra insurance to check that what is on
my local machine is identical to what's on the server (without having to
check every file and folder individually) before I sign myself off on the
job. If the count of files is different, or the most recent date is
different, I want it to give me a warning. (I want to also check the total
size, but I was getting very slightly different results with the script for
that - possibly be some invisible files or something, I'll get that working
later)
Again, thanks a lot to everyone!
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden