I rewrote my very old file system scanning code, which had been written
for Windows. When I migrated to Linux (looong time ago), I adopted
the `find' command.
The only problem I seem to have with it is that it won't find files
that begin with a tilde. I want them. I want ALL files.
Upon googling, I understand that [glob] likes to assume that the tilde
more often than not means the user's home directory. And I found this
thorough explanation by the illustrious Donal Fellows:
https://stackoverflow.com/questions/12152929/turn-off-tilde-substitution-in-filenames
Donal says:
"The simplest way to stop a leading ~ from being a problem is to put
./ in front of it, and to always use the -directory option to glob."
Well, my first version of the code was doing a [cd] before globbing
every directory so I changed that to always use the -directory option,
but that didn't solve the problem. Now I'm stumped and beg for your
help once again. The damndest thing is that the exact same [glob] line
works fine in Tkcon.
Here is my code:
set ::FILELIST {}
proc p.scan {path} {
;# SCAN FILES AND DIRECTORIES, HIDDEN OR NOT
set _ftypes {b c d f l p s hidden}
foreach type $_ftypes {
foreach _file [glob -nocomplain -tails -types $type -directory $path *] {
if {$_file == "."} {continue}
if {$_file == ".."} {continue}
set _filepath [file join $path $_file]
;# ADD FILE TO FILELIST
if {[file isfile $_filepath]} {
lappend ::FILELIST $_filepath
} else {
;# THIS LINE FOR DEBUGGING ONLY
if {! [file isdirectory $_filepath]} {puts $_filepath}
}
;# IF IT IS A DIRECTORY, GO INTO IT AND REPEAT PROCEDURE
if {[file isdirectory $_filepath] && [file type $_filepath] != "link"} {
p.scan $_filepath
cd ..
}
}
}
}
--
Luc
>>