Reputation: 119
How do I get the path without the filename in windows through Tcl? I have the full path like this:
c:\My_Designs\ipcore_script\test\src\IP_CORE\mux\sus.do
I need only the path and want to strip off the filename to get this:
c:\My_Designs\ipcore_script\test\src\IP_CORE\mux
Upvotes: 2
Views: 2825
Reputation: 119
set path1 [info script]
# get the path and file name of currently opened file
puts $path1
# shows the path
set dir1 [file dirname $path1]
# getting the directory from the fullpath
puts $dir1
Upvotes: 1
Reputation: 40224
It's dirname
, from the manual:
file dirname name
Returns a name comprised of all of the path components in name excluding the last element. If name is a relative file name and only contains one path element, then returns
.'' (or
:'' on the Macintosh). If name refers to a root directory, then the root directory is returned. For example,file dirname c:/
returns c:/.
Note that tilde substitution will only be performed if it is necessary to complete the command. For example,
file dirname ~/src/foo.c
returns ~/src, whereas
file dirname ~
returns /home (or something similar).
Upvotes: 6