Re: file with most recent modification date
Re: file with most recent modification date
- Subject: Re: file with most recent modification date
- From: Emmanuel LEVY <email@hidden>
- Date: Tue, 26 Nov 2013 16:02:47 +0100
I vaguely remember that "find" uses an index which is not always up to date - isn't it updated on saturdays at 3 am?
Emmanuel
On Nov 26, 2013, at 3:45 PM, John wrote:
> Hi Shane,
>
> This is what I use to recursively sort files...
> set folderPath to POSIX path of (choose folder)
>
> set latestFiles to paragraphs of (do shell script "find " & quoted form of folderPath & " -type f -flags nohidden \\! -name \".*\" -exec stat -f \"%Sm - %N\" -t \"%Y-%m-%d %H:%M:%S\" {} + | sort -r ;")
>
> I wrote this script to reveal the latest file in the frontmost Finder window. Map it to a keystroke or create a service for quick access.
>
> https://dl.dropboxusercontent.com/u/2422542/Reveal_Recent.zip
> John Day
>
>
>
> On Tue, Nov 26, 2013 at 6:34 AM, Shane Stanley <email@hidden> wrote:
> On 26 Nov 2013, at 8:42 PM, Emmanuel LEVY <email@hidden> wrote:
>
> > Maybe stating the obvious, I recall that the shell command "ls" supports a "-t" option to sort by modification date:
> >
> >> -t Sort by time modified (most recently modified first) before sort-
> >> ing the operands by lexicographical order.
> >
> > For scripters not familiar, that would give:
> >
> > do shell script "ls -t " & (quoted form of (posix path of theFolderAsAlias))
> >
> > More info is returned with, for instance the "l" option:
> >
> > do shell script "ls -tl " & (quoted form of (posix path of theFolderAsAlias))
>
> You raise a very good point. And it's faster (unless you include the l option). But it doesn't actually do the same job, which was to sort the *files*.
>
> You can add a -p and pass it through grep to remove directories, but unfortunately that also removes files that are packages. Being a Unix utility, ls doesn't distinguish between directories and packages. And if you do it recursively, not only can't you stop it from listing the contents of packages, but you also end up with the challenge of rebuilding the full file paths from the various fragments returned.
>
> That's not to say ls isn't without its uses -- I've used it for years, gratefully -- but it does have its limitations.
>
> --
> Shane Stanley <email@hidden>
> <www.macosxautomation.com/applescript/apps/>
>
>
> _______________________________________________
> 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
>
> _______________________________________________
> 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
_______________________________________________
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