• 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: file list as data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: file list as data


  • Subject: Re: file list as data
  • From: Shane Stanley <email@hidden>
  • Date: Thu, 24 Jul 2014 21:58:43 +1000

On 24 Jul 2014, at 7:12 pm, Christopher Stone <email@hidden> wrote:

I believe Shane's library here can be adapted to do the deed:

http://lists.apple.com/archives/applescript-users/2014/Jul/msg00012.html

No, that's not recursive. And it's probably not the most efficient way to filter by extension.

I thought he'd posted one to specifically return a recursive directory tree, but I can't seem to find it at the moment.

He hadn't, but this will do the job:

on searchDirectory:folderPOSIXPath forExtensions:extensionList
-- make NSString of folder path
set folderPathNSString to current application's NSString's stringWithString:folderPOSIXPath
-- get file manager
set fileManager to current application's NSFileManager's defaultManager()
-- ask file manager for all subpaths recursively
set theFileNSArray to fileManager's subpathsOfDirectoryAtPath:folderPOSIXPath |error|:(missing value)
-- filter the array according to extension
set theFileList to (theFileNSArray's pathsMatchingExtensions:extensionList) as list
-- combine subpaths and folder path to get full paths
set finalList to {}
repeat with aSubpath in theFileList
set end of finalList to (folderPathNSString's stringByAppendingPathComponent:aSubpath) as text
end repeat
return finalList
end searchDirectory:forExtensions:

So:

set folderPOSIXPath to POSIX path of (path to desktop)
tell script "<lib name>" to set thePaths to its searchDirectory:folderPOSIXPath forExtensions:{"asobjcex3doc"}

Using find is a whisker faster in my simple tests.

-- 
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

  • Follow-Ups:
    • Re: file list as data
      • From: Emmanuel LEVY <email@hidden>
References: 
 >Re: file list as data (From: "Jan E. Schotsman" <email@hidden>)
 >Re: file list as data (From: Bruce Robertson <email@hidden>)
 >Re: file list as data (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: file list as data
  • Next by Date: Re: codesigning results in "app is damaged" error
  • Previous by thread: Re: file list as data
  • Next by thread: Re: file list as data
  • Index(es):
    • Date
    • Thread