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)
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 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?
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
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
On 18/05/2025 03:36, Luis Alejandro Muzzachiodi wrote:
El 17/05/2025 a las 13:51, saito escribió:It seems that the caller is mangling the parameter; it will be too late by the time the proc is entered.
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
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
Thanks for your answers, but it seems I haven't been able to express my question clearly.
The question isn't about why the input isn't valid (it's a string, the slash is problematic, the spaces, etc.), but rather whether there's a reasonably simple way to make that input valid. Obviously, the simplest way would be to write the parameter "correctly." However, this comes through a procedure that allows the user to load one or more paths to add to those defined in the script, meaning it's not up to me. As I said, I tried several solutions, but they didn't work: automatically converting the parameter to a list, using the file normalize and/or nativename commands, or, as a first idea, checking whether the parameter is a list or a string (spoiler: in TCL, everything is a string...). Having said all that, I hope I've clarified the point of the question, and again, thanks for answering.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 170:42:39 |
Calls: | 13,692 |
Files: | 186,936 |
D/L today: |
100 files (20,246K bytes) |
Messages: | 2,411,676 |