File lists

Ken Ray kray at sonsothunder.com
Sat Jul 17 18:56:48 EDT 2010


> -- get a list of all OS X files in a folder
> 
> function getFiles pFolder
>    put revMacFromUnixPath(pFolder) into pFolder
>    put "tell application" && quote & "Finder" & quote & cr & "files of
> folder" \
>        && quote & pFolder & quote & cr & "end tell" into tScript
>    do tScript as "applescript"
>    put the result into tFiles
>    replace comma with cr in tFiles
>    repeat for each line l in tFiles
>      get the number of words in char 1 to offset(quote,l) of l
>      put word it of l & cr after tList
>    end repeat
>    replace quote with empty in tList
>    return tList
> end getFiles

The only suggestion I have is to be careful of the "replace comma with cr in
tFiles" line - if there's a comma in the file name you'll get a wrong
result. Also you get a bunch of extra "crap" when you have the full paths to
the files when using "files of folder <folder>".

Try this instead (watch the line wraps):

 function getFiles pFolder
    put revMacFromUnixPath(pFolder) into pFolder
    put replaceText("tell app `Finder`" & cr & \
      "the name of every file of folder `" & pFolder & "`" & cr & \
      "end tell","`",quote) into tScript
  do tScript as "AppleScript"
  put replaceText(char 3 to -3 of the result,(quote & ", " & quote),CR) into
tList
  return tList
end getFiles


Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/





More information about the use-livecode mailing list