Search code examples
tcl

Split Directory with dots and hyphen


I want to split this path so that I have the directory name as a variable. But he is interrupted.

path to splitt:

/home/user/T.A.T.E.-ano_ays-(ff-A-a)-ownage

code:

bind pub "-|-" !aaa pub:aaa
proc pub:aaa { nick uhost hand chan arg } {

    set checkpath "/home/user/T.A.T.E.-ano_ays-(ff-A-a)-ownage"
    set dirname [file rootname [file tail $checkpath]]
    putnow "PRIVMSG $chan :dirname $dirname"
}

output:

dirname T.A.T.E

correct would be: dirname T.A.T.E.-ano_ays-(ff-A-a)-ownage

How can fix the output from dirname


Solution

  • This is what file split was made for:

    % lindex [file split /home/user/T.A.T.E.-ano_ays-(ff-A-a)-ownage] end
    T.A.T.E.-ano_ays-(ff-A-a)-ownage
    

    file tail without postprocessing via file rootname would also work:

    % file tail /home/user/T.A.T.E.-ano_ays-(ff-A-a)-ownage
    T.A.T.E.-ano_ays-(ff-A-a)-ownage
    

    file rootname cuts the trailing filepath component at (not including) the last dot ..