Re: Problems with paths of Windows

Liste des GroupesRevenir à cl tcl 
Sujet : Re: Problems with paths of Windows
De : et99 (at) *nospam* rocketship1.me (et99)
Groupes : comp.lang.tcl
Date : 18. May 2025, 20:17:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <100dboq$1544i$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
On 5/18/2025 6:41 AM, Alan Grunwald wrote:
On 18/05/2025 03:36, Luis Alejandro Muzzachiodi wrote:
El 17/05/2025 a las 13:51, saito escribió:
On 5/17/2025 12:37 PM, Luis Alejandro Muzzachiodi wrote:
Hello,
>
I have a procedure that accepts a list of paths.
Assuming "$::env(SystemRoot)\my dir" is passed as a parameter, is there a way to process this so that it's interpreted correctly in the end?
I've tried combinations of { }, [list], [file normalize], [file nativename] but that didn't work.
(Working in Windows, tcl 8.6)
>
>
It is not clear what you are asking.
>
Are you trying to append a parameter to a list? You do "lappend mylist $parameter"
>
Are you trying to modify the Windows path env variable?  It is just a string separated by commas: "append env(path) \;[join $mylist \;]"
>
The question - generalizing - is how (if it is possible) to convert a path into a valid path if passed as a parameter to a procedure in the Windows format, for example, "c:\windows\my dir".
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?
>
Alejandro
>
>
>
>
>
It seems that the caller is mangling the parameter; it will be too late by the time the proc is entered.
 I suggest you try passing [file join $::env(SystemRoot) "my dir"]. If you feel that lots of up-front, non-portable string manipulation is more readable you might prefer "$::env(SystemRoot)\my dir".
 Alan
Just to (hopefully) add a little more clarity, one can see why that result occurs, with this:
% puts "$::env(SystemRoot)\my dir"
C:\WINDOWSmy dir
The \m became simply m, because of rule 9, \ followed by something NOT special (like \n), simply removes the \
Then the foreach treats it's input as though lindex were used on each item in a list:
% lindex "$::env(SystemRoot)\my dir" 0
C:WINDOWSmy
% lindex "$::env(SystemRoot)\my dir" 1
dir
Here, you are getting another round of substitution on the \W which likewise removed the \
which all together then, explains why those 2 results showed up.
In the above, one would actually need another \ as so:
% puts "|$::env(SystemRoot)\my\ dir|"
|C:\WINDOWS\my dir|
with the ||'s added to hopefully add more clarity.
-e

Date Sujet#  Auteur
17 May 25 * Problems with paths of Windows11Luis Alejandro Muzzachiodi
17 May 25 `* Re: Problems with paths of Windows10saito
18 May 25  `* Re: Problems with paths of Windows9Luis Alejandro Muzzachiodi
18 May 25   +- Re: Problems with paths of Windows1saito
18 May 25   +- Re: Problems with paths of Windows1saito
18 May 25   `* Re: Problems with paths of Windows6Alan Grunwald
18 May 25    `* Re: Problems with paths of Windows5et99
19 May 25     `* Re: Problems with paths of Windows4Luis Alejandro Muzzachiodi
19 May 25      +- Re: Problems with paths of Windows1Ralf Fassel
19 May 25      +- Re: Problems with paths of Windows1Ralf Fassel
19 May 25      `- Re: Problems with paths of Windows1et99

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal