Getting list of files in a folder
sarah.reichelt at gmail.com
Tue Feb 9 00:19:06 EST 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?
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
delete last char of tFullList
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.
More information about the Use-livecode