File lists

Kay C Lan lan.kc.macmail at gmail.com
Mon Jul 12 20:34:09 EDT 2010


On Tue, Jul 13, 2010 at 1:46 AM, J. Landman Gay <jacque at hyperactivesw.com>wrote:

>
> I found a semi-reliable solution using AppleScript. It works most of the
> time, though still doesn't cover everything, but gets almost all of it. I'll
> post it in a followup message.
>
>
>From a List post 2 Oct 2007, Subject: Packages

I wrote:

put this in a do statement:

tell application "Finder"
  files of folder "Disc:folderA:folder1"
end tell

reports only Apple recognised files in the provided location

tell application "Finder"
  folders of folder "Disc:folderB:folder2"
end tell

reports only Apple recognised folders in the provided locations

tell application "Finder"
  packages of folder "Disc:folderC:folder3"
end tell

reports only Apple recognised packages in that location.

For added convenience, but slightly confusing depending on which side of the
fence you're on, the packages are reported as either 'application files'
which are of course folders that are applications, and 'document files'
which are of course folders that look like files (.band,.rtfd,.key)

One simple test I did, was that packages are the only folders that seem to
have a '.suffix', I've never thought anyone else would actually name a
folder with a .suffix, so I did, and the above correctly identified "test
folder.test" as a simple folder.

Mark Smith then provided this:

This is great! I couldn't find this anywhere. So here's a function that uses
it - maybe someone has better code for converting the path  to applescript.

function thePackages pFolder
   set the itemdelimiter to "/"
   if item 2 of pFolder is "Volumes" then
       delete item 1 to 2 of pFolder
   else
       put line 1 of the volumes before pFolder
   end if
   replace "/" with ":" in pFolder

   put "tell application" && quote & "Finder" & quote & cr & "packages of
folder" && quote \
   & pFolder & quote & cr & "end tell" into tScr
   do tScr as applescript
   put the result into tList
   replace comma with cr in tList

   repeat for each line L in tList
       get wordoffset("file", L)
       put word it + 1 of L & cr after tPackages
   end repeat
   replace quote with empty in tPackages
   return char 1 to -2 of tPackages
end thePackages

HTH



More information about the use-livecode mailing list