Casper_Rene
Casper_Rene

Reputation: 1

Tcl search /and remove

I have a hierarchy string

Aa/bb/cc/dd
Ff/gg/hh/ii

I can get length but don't know how to get the index of last "/" How to get the output one hierarchy above?

Aa/bb/cc
Ff/gg/hh

Upvotes: 0

Views: 126

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137557

To get rid of the last component like that, use one of:

  1. regsub {/[^/]+$} $input ""not for filenames!
  2. join [lrange [split $input "/"] 0 end-1] "/"not for filenames!
  3. file dirname $input — for filenames

That has to be lifted to work over a list of values. The lmap command is convenient for that; for example:

set outputList [lmap value $inputList {file dirname $value}]

Upvotes: 1

Related Questions