Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Tonight's the night: Sleep in a eucalyptus tree.


comp / comp.lang.tcl / Issue with { char in file name

SubjectAuthor
* Issue with { char in file namealexandru
+- Re: Issue with { char in file namesaito
`* Re: Issue with { char in file nameGerald Lester
 `- Re: Issue with { char in file namealexandru

1
Subject: Issue with { char in file name
From: alexandru
Newsgroups: comp.lang.tcl
Organization: novaBBS
Date: Thu, 23 May 2024 09:04 UTC
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.quux.org!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: alexandru.dadalau@meshparts.de (alexandru)
Newsgroups: comp.lang.tcl
Subject: Issue with { char in file name
Date: Thu, 23 May 2024 09:04:01 +0000
Organization: novaBBS
Message-ID: <5febc4534980f3246825f2e60f8ce4b6@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="1959438"; mail-complaints-to="usenet@i2pn2.org";
posting-account="0Z5XV6kwM7Cos/IbgWfXZAYsazigEecpjCfqz3CX7rU";
User-Agent: Rocksolid Light
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Site: $2y$10$uw/vcAaSyQMRSbqayObiFOUavbR45oMpu8KxZhqhaJ/ynBFV1Yi7q
X-Rslight-Posting-User: 916f90664d3de2199c7a6231aba6924e4b1593d3
View all headers

I just dicovered a new issue in my code, when a file name contains one
open left curly bracket. Sure, a right bracket and other types of
brakets will case same issue.

For example, I have a file named "Test { .txt".

My code takes specific file names (only the tails, no directory) and
writes them to other files as strings.
Due to automatic char escaping happening in this process, the string
representing the file name will look like this: "Test\ \{\ 2.txt"

Which is fine.

Now my code will read those strings from the files and look them up, if
they still exists on the drive.
This is done by:

set path [file join $dir $tail]
set flag [file exists $path]

where "tail" is the variable containing the file name and "dir" is the
variable containing the directory whre the file is looked up.

The result of the "file join" command is: "C:/test2/Test/ /{/ 2.mpasm"

So all the excape chars are replaced by slash and I get the wrong file
path.

How can I avoid this issue?

Many thanks
Alexandru

Subject: Re: Issue with { char in file name
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 23 May 2024 13:00 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
Newsgroups: comp.lang.tcl
Subject: Re: Issue with { char in file name
Date: Thu, 23 May 2024 09:00:31 -0400
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <v2nelf$1omgr$2@dont-email.me>
References: <5febc4534980f3246825f2e60f8ce4b6@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 23 May 2024 15:00:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="bac127d7111c793f05d15cacf72ef984";
logging-data="1858075"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+clruJHznxOH4tFd3Ca8Wf"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:KdYuSdyz99LcE2pmMVXFSp20KOE=
Content-Language: en-US
In-Reply-To: <5febc4534980f3246825f2e60f8ce4b6@www.novabbs.com>
View all headers

On 5/23/2024 5:04 AM, alexandru wrote:
> For example, I have a file named "Test { .txt".
>
> My code takes specific file names (only the tails, no directory) and
> writes them to other files as strings.
> Due to automatic char escaping happening in this process, the string
> representing the file name will look like this: "Test\ \{\ 2.txt"
>

That is not correct. You can write the original string to a file and
read it back. It will look exactly the same.

% set data "Test { .txt"
Test { .txt

% set f [open c:/temp/filename.txt w]
file3c0b698
% puts $f $data
% close $f

% set f [open c:/temp/filename.txt r]
file3c0c058
% gets $f data2
11
% set data2
Test { .txt

Subject: Re: Issue with { char in file name
From: Gerald Lester
Newsgroups: comp.lang.tcl
Organization: fastusenet - www.fastusenet.org
Date: Thu, 23 May 2024 13:22 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx43.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Issue with { char in file name
Newsgroups: comp.lang.tcl
References: <5febc4534980f3246825f2e60f8ce4b6@www.novabbs.com>
Content-Language: en-US
From: Gerald.Lester@gmail.com (Gerald Lester)
In-Reply-To: <5febc4534980f3246825f2e60f8ce4b6@www.novabbs.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 45
Message-ID: <xqH3O.1696$aib3.1388@fx43.iad>
X-Complaints-To: abuse@fastusenet.org
NNTP-Posting-Date: Thu, 23 May 2024 13:22:37 UTC
Organization: fastusenet - www.fastusenet.org
Date: Thu, 23 May 2024 08:22:37 -0500
X-Received-Bytes: 2230
View all headers

On 5/23/24 04:04, alexandru wrote:
> I just dicovered a new issue in my code, when a file name contains one
> open left curly bracket. Sure, a right bracket and other types of
> brakets will case same issue.
>
> For example, I have a file named "Test { .txt".
>
> My code takes specific file names (only the tails, no directory) and
> writes them to other files as strings.
> Due to automatic char escaping happening in this process, the string
> representing the file name will look like this: "Test\ \{\ 2.txt"
>
> Which is fine.
>
> Now my code will read those strings from the files and look them up, if
> they still exists on the drive. This is done by:
>
> set path [file join $dir $tail]
> set flag [file exists $path]
>
> where "tail" is the variable containing the file name and "dir" is the
> variable containing the directory whre the file is looked up.
>
> The result of the "file join" command is: "C:/test2/Test/ /{/ 2.mpasm"

Can you please show us the following:

1) How you get the value into tail.
2) Any processing you to on tail before using it.
3) How you build and write the strings to the output file
4) How you read and process the strings in the input file

>
> So all the excape chars are replaced by slash and I get the wrong file
> path.
>
> How can I avoid this issue?
>

I'm almost certain at some point in one or more of those four steps you
switch between string and list operations.

To avoid it, treat strings as strings and list as lists.

Subject: Re: Issue with { char in file name
From: alexandru
Newsgroups: comp.lang.tcl
Organization: novaBBS
Date: Thu, 23 May 2024 17:28 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: alexandru.dadalau@meshparts.de (alexandru)
Newsgroups: comp.lang.tcl
Subject: Re: Issue with { char in file name
Date: Thu, 23 May 2024 17:28:25 +0000
Organization: novaBBS
Message-ID: <8ee301ada71d4e9358c65041165d95ca@www.novabbs.com>
References: <5febc4534980f3246825f2e60f8ce4b6@www.novabbs.com> <xqH3O.1696$aib3.1388@fx43.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="1997982"; mail-complaints-to="usenet@i2pn2.org";
posting-account="0Z5XV6kwM7Cos/IbgWfXZAYsazigEecpjCfqz3CX7rU";
User-Agent: Rocksolid Light
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Posting-User: 916f90664d3de2199c7a6231aba6924e4b1593d3
X-Rslight-Site: $2y$10$wqVoy9f.e/tJRWt9l7.DMOZoFiti79BD2enS/xQsMOTKKdqqDGUae
View all headers

Thanks! You answers got me thinking.
The issue was caused by writing data as a list, not as a string.
Problem solved.
Regards
Alexandru

1

rocksolid light 0.9.8
clearnet tor