File Walker

Alex Tweedly alex at tweedly.net
Tue Sep 30 18:45:34 EDT 2014


On 30/09/2014 21:32, JB wrote:
> And what do you mean by folders that cannot
> be accessed?  Since when are they not able
> to be accessed?  I access them all of the time.
> I am a typical user who accesses files & folders
> everyday the same way.

Yes, most folders and files can be accessed. But there are *some* 
folders that cannot be accessed, and because File Lister tries to access 
every folder within the starting folder, it will find those few that 
cannot be accessed - even though they may never be encountered any other 
time.

There are a variety of reasons for folders being inaccessible.

1. Permissions.
Try this (in Terminal or other shell).
mkdir sub
cd sub
pwd
      --- it properly shows you as being in ....../sub
cd ..
chmod 000 sub    (i.e. make the folder inaccessible)
cd sub
    -- gives an error message of permission denied

Similarly, if you no wtry to access in Finder, it will just not "go" 
into that directory.
And if you run the original "File Lister 2", it will wrongly report a 
recursion limit reached; you need a safety check - whether the one I 
gave or another equivalent - to be added.



2. "Not really a folder"

There are various pseudo-folders within application bundles that aren't 
really folders. You would be unlikely to encounter these in Finder - it 
doesn't even show the top level of folders with "Applications". Even in 
Terminal, they are hidden - but they are there, and are seen by File 
Lister - and in some cases they are inaccessible, so caused the apparent 
"recursion" error report.

3. This is a Livecode issue !!!   Non-ASCII characters in filenames
I have some albums in my iTunes library by foreign artists (Icelandic), 
who have characters from the extended character set in their names. In 
LC, those don't come out right - so they also fail with the (incorrect) 
recursion report. My earlier suggested addition to the code will avoid 
this becoming a problem - though you do still have an issue.  I suspect 
that with LC 7.0 this will cease to be a problem - though it might still 
need a "URLEncode" or two to fix it completely.

4. Weird folders (:-)

Inside my iBooks library there are a number of weird folders - they show 
up looking like garbage names in LC, and also in Finder and in Terminal. 
They have permissions set to allow access - but in fact they don't - to 
Finder and terminal as well as to LC.
>
> So you are telling me they cannot be accessed
> and I encourage you to put a program on the
> market and explain that to those who access
> their folders every day and your program does
> not allow them to access it.
Remember - most if not all of these 'folders' aren't really folders, so 
don't contain users' files, don't contain user accessible data, and 
won't be seen by users.
> They will read your response and quit your program
> and continue to access their folders as usual and you
> will not hear from them again because they do not want
> to spend their time explaining to you they are able to
> access their folders without your program.
No, they won't - because (with the modified code) they will be able to 
see all (*) the files and folders they can see in Finder.
(*) with the exception of the Unicode issues mentioned in 3 above.
>
> If it causes me problems it will cause someone else
> problems and I am not going to explain to them do
> not use those folders with my program or block it
> and give them a dialog stating it cannot be accessed.
>
> I liked the idea of recursive but it does not work good
> for me.
It's not "recursive" that's the problem - my non-recursive version had 
exactly the same issue (in its first version). Attached below is an 
updated version with the 'safety check' that should have been there in 
the first place - it now builds a list of "inaccessible' folders in 
global variable 'gFailedFolders' as well as the list of files and folders.
(btw - I also changed one "after" to "before" - a marginal extra cost in 
LC processing, but gains a large benefit in file access locality).



on dirWalk whatFolder
    local temp, tCount, tDirList, tDirsToDo
    set the itemDel to "/"
    set the directory to whatFolder
    put whatfolder &CR into tDirsToDo
    repeat forever
       put line 1 of tDirsToDo into whatFolder
       set the directory to whatFolder
       delete line 1 of tDirsToDo
       if the directory <> whatfolder then
          put whatfolder &CR after gFailedFolders
          if the number of lines in tDirsToDo = 0 then exit repeat
          next repeat
       end if
       put the files into temp
       add the number of lines of temp to tCount
       sort temp
       repeat for each line x in temp
          put whatFolder & "/" & x & cr after gHierList
       end repeat
       put the folders into tDirList
       sort tDirList
       delete line 1 of tDirList
       repeat for each line x in tDirList
          put whatFolder & "/" & x & CR before tDirsToDo
       end repeat
       if the number of lines in tDirsToDo = 0 then exit repeat
    end repeat
end dirWalk

- Alex.




More information about the use-livecode mailing list