# Find the longest correct path within a given path proc CorrectPath {path} { set correctPath "/" foreach fileName [file split $path] { set testedPath $correctPath lappend testedPath $fileName if [file isdirectory [file join $testedPath]] { set correctPath $testedPath } else { break } } return $correctPath } puts [CorrectPath "/ftp/aux"]