• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Return file list sorted by modification date instead of alphabetically
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Return file list sorted by modification date instead of alphabetically


  • Subject: Re: Return file list sorted by modification date instead of alphabetically
  • From: "Terrazas, Enrique" <email@hidden>
  • Date: Wed, 12 Mar 2014 23:54:34 +0000
  • Thread-topic: Return file list sorted by modification date instead of alphabetically

In a terminal window type “man ls” (followed by a return)
Reading down a little, the -1 option is explained:

    -1      (The numeric digit ``one''.)  Force output to be one entry per
             line.  This is the default when output is not to a terminal.

ls by itself will list more than one file per line.  By piping " ls - t " output to cat (the " ls -t | cat “ part), you are not sending to a terminal, so it ends up as 1 filename per line.  You can type “man cat” in a terminal window to read more on what cat does.  I didn’t realize that Mac OSX’s ls command supported the -1 option, which means you don’t need to pipe to cat to get 1 filename per line.

I have ls aliases to "ls -GF” … type that in a terminal window to see what the output looks like.  By specifying the path (/bin/ls) you bypass any aliasing of commands that may be occurring.

Shell scripting can be very powerful, so it may be useful to invest in a good unix or linux reference that includes a good bit of shell scripting information.

Enrique Terrazas

On Mar 12, 2014, at 3:55 PM, Bert Groeneveld <email@hidden> wrote:

Enriques solution(s) work perfectly! Thank you Enrique. Can you explain a little bit what the differences are between the lines? Just to learn something from it. What do you mean with "fancy output"? Your code is also shorter than the one I already had (see below example 4), and it does even more (the sorting I mean).
I do a lot of applescripting (especially InDesign), but I don't know anything about Unix commands.

Anyway, thanks a lot for your solution! 
Bert.

1) set all_the_Hires_Images to paragraphs of (do shell script "cd " & qp & "&& ls -1t")
2) set all_the_Hires_Images to paragraphs of (do shell script "cd " & qp & "&& ls -t | cat")
3) set all_the_Hires_Images to paragraphs of (do shell script "cd " & qp & "&& /bin/ls -1t")
4) set all_the_Hires_Images to paragraphs of (do shell script "cd " & qp & "&& find . -type f -print | sed -e 's,.*/,,'")

On 12 mrt. 2014 (week 11), at 21:42, "Terrazas, Enrique" <email@hidden> wrote:

Sorry, my previous email bounced (sent from wrong account) … this should also work

set all_the_Hires_Images to paragraphs of (do shell script "cd " & qp & "&& ls -1t")

the numerical 1 tells ls to produce one filename per line
If you have ls aliased to produce fancy output, you may want to include the full path i.e. “&& /bin/ls -1t"

Enrique Terrazas

On Mar 12, 2014, at 1:21 PM, Enrique Terrazas <email@hidden> wrote:

Try this:

set all_the_Hires_Images to paragraphs of (do shell script "cd " & qp & "&& ls -t | cat")

ls -t gives you a reverse sorted list by modification time
the pipe to the cat command is to produce a list with a single filename per line

Enrique Terrazas

On Mar 12, 2014, at 1:04 PM, Bert Groeneveld <email@hidden> wrote:

Hi Luther,

What I am looking for is speed. The image folder contains 25000 jpg files. And Mark's script returns a list of 25000 filenames in just a couple of seconds (even if the image folder is a network mount).
Your Finder script is much too slow (and it returns the full paths instead of only the filenames). I need speed, that's why I need the shell script instead of a Finder script. Unfortunately I really wouldn't know how to edit Mark's script in a way that the list is sorted by modification date with the newest first (instead of alphabetically).

Anyway, thank you for your answer.

- - - - - - - - - - - - - - - - - -


On 12 mrt. 2014 (week 11), at 20:08, Luther Fuller <email@hidden> wrote:

This looked familiar, so I looked in an old script and found ...

set rawMsgList to (reverse of (sort {get items of sourceFolder} by modification date)) -- Leopard needs {}

So, I did some experimenting. Like this ...

property sourceFolder : alias "OS_X:Library:Application Support"
on run
tell application "Finder"
-- set fileList to sort (get items of sourceFolder) by modification date
set fileList to (reverse of (sort (get items of sourceFolder) by modification date))
end tell
item 1 of fileList as text
log the result
end run

This seems to do what you need ... and does not need 'do shell script'.
(But, perhaps you had something else in mind that I overlooked. ?)

On Mar 12, 2014, at 10:06 AM, Bert Groeneveld wrote:


Thanks to Mark J. Reed I have following very, very powerful piece of code:
set all_the_Hires_Images to paragraphs of (do shell script "cd " & qp & "&& find . -type f -print | sed -e 's,.*/,,'")

I use it this way:
set the_ImagePath_folder to choose folder with prompt "Choose Hires Folder"
set qp to quoted form of POSIX path of the_ImagePath_folder
set all_the_Hires_Images to paragraphs of (do shell script "cd " & qp & "&& find . -type f -print | sed -e 's,.*/,,'")
(*  Finder alternative (much slower)
tell application "Finder"
set all_the_Hires_Images to name of every file of entire contents of the_ImagePath_folder 
end tell
*)
This script returns a list (sorted alphabetically) of the NAMES of all files inside a certain highres folder. So far so good.

What I need now is the same list, but than sorted by modification date with the newest files first (instead of sorted alphabetically). Is someone able to help me and edit Mark's code? I am unable to figure this out myself.

Thank you for any help, Bert.



 _______________________________________________
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

  • Follow-Ups:
    • Re: Return file list sorted by modification date instead of alphabetically
      • From: Christopher Stone <email@hidden>
References: 
 >Return file list sorted by modification date instead of alphabetically (From: Bert Groeneveld <email@hidden>)
 >Re: Return file list sorted by modification date instead of alphabetically (From: Luther Fuller <email@hidden>)
 >Re: Return file list sorted by modification date instead of alphabetically (From: Bert Groeneveld <email@hidden>)
 >Re: Return file list sorted by modification date instead of alphabetically (From: "Terrazas, Enrique" <email@hidden>)
 >Re: Return file list sorted by modification date instead of alphabetically (From: Bert Groeneveld <email@hidden>)

  • Prev by Date: Re: Return file list sorted by modification date instead of alphabetically
  • Next by Date: Re: Return file list sorted by modification date instead of alphabetically
  • Previous by thread: Re: Return file list sorted by modification date instead of alphabetically
  • Next by thread: Re: Return file list sorted by modification date instead of alphabetically
  • Index(es):
    • Date
    • Thread