recursion limit when creating file list of harddrive

Peter M. Brigham pmbrig at gmail.com
Fri Oct 30 08:57:44 EDT 2015


Here is a version that puts the trailing "/" on folders and adjusts the input parameters for the function.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig

--------------

function directoryListing pWhatFolder, pInvisibleFiles, pDepth
   -- returns a full listing of the files/folders in a given folder
   -- pass pInvisibleFiles = true if you want to list invisible files
   --    if false or no value passed, then will list only visible files
   -- pDepth is the maximum depth you want to penetrate to
   --    if no value passed, then will list all files at all depths
   
   if pInvisibleFiles = empty then put false into pInvisibleFiles
   if pDepth = empty then put 0 into pDepth
   if char -1 of pWhatFolder <> "/" then put "/" after pWhatFolder
   put pWhatFolder & cr into R
   set the directory to pWhatFolder
   if pDepth = 1 or the result is not empty then return R
   put the files into tFileList
   sort tFileList
   replace cr with cr & pWhatFolder in tFileList
   put pWhatFolder & tFileList & cr after R
   put line 2 to -1 of the folders into tDirList
   sort tDirList
   repeat for each line L in tDirList
      put directoryListing((pWhatFolder & L),pInvisibleFiles,pDepth-1) after R
   end repeat
   if not pInvisibleFiles then
      filter R without "*/.*"
   end if
   return R
end directoryListing

On Oct 29, 2015, at 8:49 AM, Geoff Canyon wrote:

> "there is a folder" and "there is a file" can distinguish between the two.
> Obviously if you want to distinguish visually for the user, or to do it
> without testing, then including the trailing "/" would work.
> 
> On Wed, Oct 28, 2015 at 1:51 PM, Michael Doub <mikedoub at gmail.com> wrote:
> 
>> When I saw that the output contained both directories and files, adding
>> the "/" allows you to
>> easily know that you are looking at a folder rather than a file.
>> 
>> put directoryListing(whatfolder) into foo
>> repeat for each line x of foo
>> if char -1 of x = "/" then
>>     put x & cr after directoryList
>> else
>>     put x & cr after fileList
>> end if
>> 
>> Given a random path that could be either a directory or a file, is there a
>> clever way to tell what you have?
>> 
>> -= Mike
>> 
>> 
>> On 10/28/15 10:55 AM, Geoff Canyon wrote:
>> 
>>> The trailing "/" is an interesting point. I checked and the "set the
>>> directory" command will happily take a trailing "/" or not, but when you
>>> "put the directory" you get no trailing "/"
>>> 
>>> Given that, I'd probably leave it as is, and always assume that the
>>> description of a particular directory needs to have the "/" added when
>>> adding a filename or directoryname to it.
>>> 
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list