Getting list of files in a folder

Sarah Reichelt sarah.reichelt at gmail.com
Mon Feb 8 23:19:06 CST 2010


On Tue, Feb 9, 2010 at 3:05 PM, Mark Swindell <mdswindell at cruzio.com> wrote:
> How do I return a list of the files in a given folder on disk along with their full path?

Manually :-)

Here is a function I wrote that lists files in a folder for you,
resetting the defaultFolder when it's got the list.

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


If you use:
   put listFiles(tFolder) into fld "Files"
you get tust the file names, but if you use:
   put listFiles(tFolder, "full") into fld "Data"
you will get the full file paths.

Cheers,
Sarah



More information about the use-livecode mailing list