• 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
The alternative to the deprecated 'list folder'
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The alternative to the deprecated 'list folder'


  • Subject: The alternative to the deprecated 'list folder'
  • From: Harald E Brandt <email@hidden>
  • Date: Wed, 19 Mar 2008 17:10:12 +0100

The StandardAdditions command 'list folder' is deemed deprecated, and Apple says one should use System Events instead.
However, on a folder with many items, that is really a bad recommendation, as is shown below:
 
Example folder has 3794 visible files.
The deprecated command 'list folder' needs to have an 'alias' or 'file' after it in order to avoid bugs, like this:
list folder file theFolderPath without invisibles
Timing this gets me between 90 and 149 ms.

The System Events version, but including invisibles, is:
tell application "System Events" to get name of files in folder theFolderPath
Timing this gets me between 490 and 780 ms!
Pretty unacceptable slowdown by itself, but it does not even do what we want!

It really should be as follows:
tell application "System Events" to get name of files in folder theFolderPath whose visible is true
However, that will timeout and crash System Events!!

By far the best alternative is to use the Unix 'ls' in a do shell script, thus:
paragraphs of (do shell script "ls " & quoted form of POSIX path of theFolderPath)
Timing this gets me between 42 and 46 ms! I.e even better than the old 'list folder'!

On Leopard and Tiger, it also works for files with "funny names" (non ascii).
(But 'ls' will also list an "invisible" Icon-file if it exists, but that is no big deal.)

The reason I needed to investigate this is that I was dumb enough to simply replace a 'list folder' I had in a product I sell, with the "corresponding" System Events surrogate. I only tested that it worked, but didn't realize it was going to crash if the number of files is large.

/h

______heb____________________________
Harald E Brandt     http://bragit.com



 _______________________________________________
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: The alternative to the deprecated 'list folder'
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Toxic Soup and Enough for all
  • Next by Date: Re: Abs function broken on leopard?
  • Previous by thread: Re: Abs function broken on leopard?
  • Next by thread: Re: The alternative to the deprecated 'list folder'
  • Index(es):
    • Date
    • Thread