I am trying to open a folder from tcl/tk using the below command
eval exec [auto_execok start] [list $folderpath]
it gives me error on syntax is incorrect.
in the tclsh command prompt when I tried
start $folderpath the folder opens.
Any help is appreciated.
The code you were using is almost correct. You wanted this:
That’s because you needed that extra blank argument in there for
startto consume (it’s the “title” of the window to create, and is rather obscure if you’re used to only feeding in relative filenames). This is a specific quirk ofstart, combined with how Tcl does the quoting of things being fed through the Windows process creation interface; what happens is that Tcl puts"chars round non-simple arguments (almost always the right thing to do) and that causesstartto get confused and do the wrong thing, which leads to the error message. This is pretty horrible, but adding an extra empty argument defuses the problem.You might also need to convert that path into the native format if it isn’t already:
(How do you know if it is native? Check if the directory separator is
/— the Tcl standard, also native on Unix and OSX — or\— which Windows uses.)In some cases, you may need
file attributes $folderpath -shortnameto work around problems. I hope you don’t need that! (Hardly anything does these days, to be fair; it was only critical on pre-XP systems though it remains occasionally useful when dealing with very long paths.)Compatibility Forms
You are encouraged to use the syntactic changes proposed by Glenn if you’re using Tcl 8.5 (or later), as they’re clearer, easier to use, and marginally faster too (not that the last matters much here; the speed difference will be just noise compared to the cost of starting a subprocess):
If you’re using 8.4 (elderly, but supported) or before (why!?) then use the form with
evalforms above.