Lucas Oliveira
Lucas Oliveira

Reputation: 191

String manipulation - getting file name from absolute file path

I have a variable containing a path to a file, that I obtain from the tk_getOpenFile function, the $file variable would be something like this:

/home/usr/Documents/Plugin-2-Linux.pdpk

I need some sort of split to get only the Plugin-2-Linux. Please note that the path may not be the same every time. So what I need is to get the string between the last / and the .pdpk and put it in another variable: $filename.

Upvotes: 2

Views: 1834

Answers (1)

Brad Lanam
Brad Lanam

Reputation: 5723

set filename [file rootname [file tail $file]]

file tail returns the part after the last / (not counting trailing /s), and file rootname the part before the last ..

man page for file

Upvotes: 5

Related Questions