2017-06-12 55 views
1

我想一個文件名追加到TCL項目目錄追加字符串:串接/在TCL

set filename hello 
set currentPath "D:/TEMP/project name/subfolder/" 
puts [append $currentPath $filename] 

按照docs所有需要的是一個varName,這是我們的追加和後附於varName。不幸的是,當我運行上面的代碼時,我只輸出hello。我如何在TCL上執行這個簡單的任務?

回答

2

問題是,您正在使用變量,您需要變量名稱。在Tcl中(與其他一些語言相反),$的意思是「讀取這個變量現在」,這意味着你給一個相當奇怪的變量名稱append。嘗試從切換:

puts [append $currentPath $filename] 

到:

puts [append currentPath $filename] 
# Be aware that this *updates* the currentPath variable 

另外,如果你想利用這個做一個文件名,也可以考慮使用file join代替;它處理你目前不知道的各種棘手的情況,以至於你永遠不需要知道它們。

puts [file join $currentPath $filename]