Getting list of files in a folder
Phil Davis
revdev at pdslabs.net
Tue Feb 9 00:38:10 EST 2010
Hi Mark,
Gotta love this list! I'm not really trying to improve on the solutions
from Terry and Sarah, just offering an alternative.
Instead of prepending each filename with the path via a repeat loop like
this:
repeat for each line L in tFileList
put pFolder& L& cr after tFullList
end repeat
You could do it this way:
put (CR & tFileList) into tFullList
replace CR with (CR & pFolder) in tFullList
delete char 1 of tFullList
So you have 3 lines that execute, even with a list of 1000 files. I
haven't timed this to see if there's a speed gain - just thought I would
throw it out there.
Phil Davis
On 2/8/10 9:20 PM, Mark Swindell wrote:
> Terry, Sarah,
>
> Wow, that was fast! Thank you so much.
>
> Mark
>
> On Feb 8, 2010, at 9:19 PM, Sarah Reichelt wrote:
>
>
>> 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
>>
--
Phil Davis
PDS Labs
Professional Software Development
http://pdslabs.net
More information about the use-livecode
mailing list