Reputation: 128
I look for a code for saving the current path of running tcl script. Ive found already a code but it doesnt works.
proc getScriptDirectory {} {
set dispScriptFile [file normalize [info script]]
set scriptFolder [file dirname $dispScriptFile]
return $scriptFolder
}
has anybody an idea?
Upvotes: 0
Views: 1768
Reputation: 137807
The info script
command works, but only when the script is running and not when the procedures it creates are running. You have to save the value when the code runs so that you can use it later.
# The two-argument version of [variable] initialises the variable's value
variable dispScriptFile [file normalize [info script]]
proc getScriptDirectory {} {
variable dispScriptFile
set scriptFolder [file dirname $dispScriptFile]
return $scriptFolder
}
There's not usually a significant problem with variable pollution when doing it this way as you can use a variable in the namespace that you're defining, and almost always when you want this you are defining a namespace.
Upvotes: 2