Listing files in a folder

Sarah Reichelt sarah.reichelt at gmail.com
Thu Oct 27 00:40:41 EDT 2005


Hi All,

I got sick of listing files in various folders and having to set the
default folder to do so, and then having to remember to set it back
afterwards. You can't  use "the files" to list files in anything other
than the default folder, so here is the function I wrote to handle
this boring stuff for me. It may be of no interest to most people, but
I am currently working on an app that has to examine multiple folders
and transfer files around, so it is saving me a lot of typing.

The first parameter is the path to a folder. The second parameter
dictates whether the full file path for each file should be returned,
or just the file name. It can be any of true, yes or full.

Cheers,
Sarah


function listFiles pFolder, pGiveFullPath
  if there is not a folder pFolder then return empty

  -- get the list of files & reset default folder
  put the defaultFolder into tOldDefault
  set the defaultFolder to pFolder
  put the files into tFileList
  set the defaultFolder to tOldDefault

  -- filter out OS X's invisible files
  filter tFileList without ".*"

  -- add folder path to file name if required
  if pGiveFullPath is among the items of "true,yes,full" then
    put empty into tFullList
    if the last char of pFolder <> "/" then put "/" after pFolder
    repeat for each line L in tFileList
      put pFolder & L & cr after tFullList
    end repeat
    delete last char of tFullList
    return tFullList

  else
    return tFileList
  end if
end listFiles



More information about the use-livecode mailing list