• 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: AppleScriptObjC -- List Folder Handler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScriptObjC -- List Folder Handler


  • Subject: Re: AppleScriptObjC -- List Folder Handler
  • From: Nigel Garvey <email@hidden>
  • Date: Sun, 02 Dec 2018 00:42:42 +0000

Shane Stanley wrote on Sat, 01 Dec 2018 15:42:23 +1100:

>on listFolder:targetDir returningAs:returnType -- "furl", "path",
"name",
>"displayed name"
>       set NSDirectoryEnumerationSkipsHiddenFiles to a reference to 4
>       set NSFileManager to a reference to current application's NSFileManager
>       set {theURLs, theError} to NSFileManager's defaultManager()'s
>contentsOfDirectoryAtURL:targetDir includingPropertiesForKeys:{}
>options:(NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference)
>       if theURLs is equal to missing value then error (theError's
>localizedDescription() as text)
>       if returnType = "furl" then
>               return theURLs as list
>       else if returnType = "path" then
>               return (theURLs's valueForKey:"path") as list
>       else if returnType = "name" then
>               return (theURLs's valueForKey:"lastPathComponent") as list
>       else if returnType = "displayed name" then
>               set theNames to {}
>               repeat with aURL in theURLs
>                       set {theResult, theName} to (aURL's
> getResourceValue:(reference)
>forKey:(current application's NSURLLocalizedNameKey) |error|:(missing
>value))
>                       set end of theNames to theName as text
>               end repeat
>               return theNames
>       end if
>end listFolder:returningAs:
>
>As you can see, it's quite a bit slower.

Hi.

It can be speeded up considerably for large folders by fetching the keys
with the URLs, and a bit more by building theNames as an NSMutableArray:

  on listFolder:targetDir returningAs:returnType -- "furl", "path", "name",
"displayed name"
    set NSDirectoryEnumerationSkipsHiddenFiles to a reference to 4
    set NSFileManager to a reference to current application's NSFileManager
    set {theURLs, theError} to NSFileManager's defaultManager()'s
contentsOfDirectoryAtURL:targetDir includingPropertiesForKeys:{current
application's NSURLLocalizedNameKey}
options:(NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference)
    if theURLs is equal to missing value then error (theError's
localizedDescription() as text)
    if returnType = "furl" then
      return theURLs as list
    else if returnType = "path" then
      return (theURLs's valueForKey:"path") as list
    else if returnType = "name" then
      return (theURLs's valueForKey:"lastPathComponent") as list
    else if returnType = "displayed name" then
      set theNames to current application's NSMutableArray's new()
      repeat with aURL in theURLs
        set {theResult, theName} to (aURL's getResourceValue:(reference)
forKey:(current application's NSURLLocalizedNameKey) |error|:(missing value))
        (theNames's addObject:(theName))
      end repeat
      return theNames as list
    end if
  end listFolder:returningAs:


NG

 _______________________________________________
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: AppleScriptObjC -- List Folder Handler
      • From: Nigel Garvey <email@hidden>
    • Re: AppleScriptObjC -- List Folder Handler
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: AppleScriptObjC -- List Folder Handler
  • Next by Date: Re: AppleScriptObjC -- List Folder Handler
  • Previous by thread: Re: AppleScriptObjC -- List Folder Handler
  • Next by thread: Re: AppleScriptObjC -- List Folder Handler
  • Index(es):
    • Date
    • Thread