remove file path and extension in Tcl command
Asked Answered
tcl
S

1

5

say the file path is saved as an variable f

puts "$f"

Then outcome is

/home/usr/testfile.txt

I want to remove everything but the name, 'testfile' and save it in a new variable.

Spectrogram answered 22/9, 2015 at 22:51 Comment(0)
E
20

The file command is what you want.

 set fbasename [file rootname [file tail $f]]

file tail is the last component of the filename. file rootname is everything excepting the extension.

Empoison answered 22/9, 2015 at 23:6 Comment(1)
Hi, is there a fast way of doing the same thing in shell script? Instead of using 'cut' command?Spectrogram

© 2022 - 2024 — McMap. All rights reserved.