Sujet : Re: Problems with paths of Windows
De : saitology9 (at) *nospam* gmail.com (saito)
Groupes : comp.lang.tclDate : 18. May 2025, 05:42:57
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <100bogh$quv6$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 5/17/2025 10:36 PM, Luis Alejandro Muzzachiodi wrote:
The specific question would be:
given the following procedure
proc myproc { listofpaths } {
foreach p $listofpaths {
puts "$p - is valid? : [file isdirectory $p]"
}
}
if a parameter is passed as "$::env(SystemRoot)\my dir"
the result obtained is
C:Windowsmy - is valid? : 0
dir - is valid? : 0
Then, is there a way to convert - within the procedure - that input into a valid directory?
OK, that clarifies it. So your proc is correct as above. Here is a test:
% myproc [list [file join $::env(SystemRoot) "Offline Web Pages"]]
C:/WINDOWS/Offline Web Pages - is valid? : 1
What is causing trouble is a combination of a couple of factors: basic Tcl quoting involving spaces and the unfortunate use of backslash by Windows and Tcl for different purposes. In general, I would recommend using [file] commands like the test above to construct file names as opposed to what you are doing with "$::env(SystemRoot)\my dir".
If you insist on doing it your way, you need to escape the spaces as well as the backslash that Windows uses as file separator. Here is an example:
% myproc [list "$::env(SystemRoot)\Offline\ Web\ Pages"]
C:\WINDOWS\Offline Web Pages - is valid? : 1
Note that each space is escaped with a backslash, and the file separator backslash is escaped as well with an extra backslash. But really it goes back to the basics of quoting.