File lists

J. Landman Gay jacque at hyperactivesw.com
Sun Jul 11 23:02:44 EDT 2010


Andre Garzia wrote:
> Jacque,
> 
> For your mac os x programming pleasure:

Thanks. After staring at the problem all afternoon, I think I garbled my 
request due to Fuzzy Brain Syndrome. What I need is a list of both 
regular files and files that happen to be bundles, but does not include 
apps, system things, or user folders. In other words, a list of any file 
the user can double-click that would launch an app.

I can filter out apps by checking their extension. Now I need to figure 
out how to remove user folders without removing bundles that are 
actually user files, like the ones iApps make.

I got this far:

function getFiles -- assume directory is already set
   put shell("ls -AF") into tFiles -- the "A" skips dot files
   filter tFiles without ".*" -- but it doesn't strip .DS_Store :(
   filter tFiles without "*.app*" -- remove apps
   repeat for each line l in tFiles
     if last char of l <> slash then -- normal file
       put l & cr after tList
     else -- bundle or folder; remove user folders, keep files
       put l & "Contents/PkgInfo" into tTestFile
       if there is a file tTestFile then -- iApp file
         put char 1 to -2 of l & cr after tList
       else if VOODOO -- MAGIC FILE TEST
          -- MIRACULOUS IDENTIFICATION, ADD TO LIST
       end if
     end if
   end repeat
   return tList
end getFiles

Checking for the pkgInfo file also eliminates plugins and .bundle files, 
at least the ones I looked at. Not sure where to go from here, I need to 
catch .rtfd files and similar. The .rtfd folders just contain a bunch of 
regular files (and no Content folder,) which makes those bundles 
indistinguishable from a user folder if you're just looking at file paths.

I just discovered the "ls -F" shell command, which is handy because it 
gives a list of everything, with folders marked by a trailing slash. 
That way you don't have to get the files and the folders separately and 
then combine them.

I'll look at the link you and Mike Bonner mentioned, it does sound like 
I need to look at some file flags. But if anyone's done this already I'd 
love to freeload.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list