Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

A mathematician is a device for turning coffee into theorems. -- P. Erdos


devel / comp.lang.tcl / Re: Globbing files with tilde

SubjectAuthor
* Globbing files with tildeLuc
+- Globbing files with tildeRich
`- Globbing files with tildeChristian Gollwitzer

1
Globbing files with tilde

<20221211010622.08155bb5@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10329&group=comp.lang.tcl#10329

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!zOaEeTyrtYd+hIKjaExfSw.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Globbing files with tilde
Date: Sun, 11 Dec 2022 01:06:22 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221211010622.08155bb5@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="7816"; posting-host="zOaEeTyrtYd+hIKjaExfSw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Luc - Sun, 11 Dec 2022 04:06 UTC

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
>>

Re: Globbing files with tilde

<tn3rie$1sofi$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10331&group=comp.lang.tcl#10331

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Globbing files with tilde
Date: Sun, 11 Dec 2022 05:58:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <tn3rie$1sofi$1@dont-email.me>
References: <20221211010622.08155bb5@lud1.home>
Injection-Date: Sun, 11 Dec 2022 05:58:38 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="f90df1f022427ba91905349c5986926e";
logging-data="1991154"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+TeuCnmYhZHUczoRExtp/p"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:FHxFqqZRdulDcH8tz/zhATLlK6M=
 by: Rich - Sun, 11 Dec 2022 05:58 UTC

Luc <no@no.no> wrote:
> 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.

Which 'it' do you mean, the GNU 'find' command, or TCL's 'glob'?

And for me, both seem to find files with tilde's just fine:

Test directory contents:

$ ls -1
end~
mid~dle
~begin

GNU find inside the test directory:

$ find -type f
./~begin
./mid~dle
./end~

TCL's glob inside the same test directory:

$ rlwrap tclsh
% join [glob *] \n
~begin
mid~dle
end~
%

Both found files with tilde's at the beginning, in the middle, and at
the end.

Re: Globbing files with tilde

<tn40bb$1t1lr$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10332&group=comp.lang.tcl#10332

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: aurio...@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: Globbing files with tilde
Date: Sun, 11 Dec 2022 08:20:11 +0100
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <tn40bb$1t1lr$1@dont-email.me>
References: <20221211010622.08155bb5@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 11 Dec 2022 07:20:11 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="646d57ad5d74ddfbabf4c0849585b4e4";
logging-data="2000571"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PqdjHiKIFnKoqrP58YjRpyoUeCt5Y+BM="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:102.0)
Gecko/20100101 Thunderbird/102.5.0
Cancel-Lock: sha1:Fw81Ls6tQI0HalvacieFKM8zaa4=
In-Reply-To: <20221211010622.08155bb5@lud1.home>
 by: Christian Gollwitzer - Sun, 11 Dec 2022 07:20 UTC

Am 11.12.22 um 05:06 schrieb Luc:
> 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.

It is worse than that: ALL commands working on files expand the leading
tilde into home directories. Thankfully, this misfeature will be removed
in Tcl9 https://core.tcl-lang.org/tips/doc/trunk/tip/602.md

But "glob" returns the ~files unmodified, therefore this does not work:

foreach fn [glob *] {
lappend fds [open $fn]
}

Here, a ~file in the current directory will lead "open" to fail.

> 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]}

I think that the bug is in here. "file isfile" and "file join" fail due
to the ~problem:

(kbskit) 50 % file join /temp ~test
~test

You need to do:

(kbskit) 51 % file join /temp ./~test
/temp/~test

But beware that this is not always what you want to do: In case the
second part really is an absolute path (can't happen in your case now),
you don't want the prefix:

(kbskit) 55 % file join /temp /test
/test
(kbskit) 56 % file join /temp .//test
/temp/./test

Christian

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor