2014-12-26

TCL, File - Get file path

[Condition]
  • filename: test.tcl
  • file path: C:/02-MTS/99-Trainning/12-info/

set appPath [ file normalize [ info script ] ]

if { [file type $appPath ] == "link" } {
      set appPath [ file readlink $appPath ]
}

puts $appPath

[Program Output]
  • C:/02-MTS/99-Trainning/12-info/test.tcl

<< Description of Syntax >>
  • file normalize [ info script ]
    • info script
      • 回傳正在執行中的檔案路徑.
    • file normalize
      • 解析檔案路徑中的 ".." 和 "," 符號, 並回傳處理後的結果.
  • [ file type $appPath ] == "link"
    • file type $appPath
      • 判斷檔案或目錄的類型, 回傳是 file, directory or link.
      • == link --> 回傳的是是否為 link.
  • file readlink $appPath
    • 讀取 $appPath 的檔案路徑並回傳值.

沒有留言:

張貼留言