I have a set of files which break up my program into sections, such
as GUI, tooltips, procedures etc. The GUI interface is my main
program from which I want to source the other Tcl programs, all in
the same directory. Obviously I can use: cd C:/dir/dir.... and then
just use source <file>
BUT, I'd like to be able to do this from whatever directory the files
all happen to be in, so I need a generic way of "cd-ing" to the dir
wherever it is.
I thought something like set x [pwd]
then... cd $x would work? Apparently not.
Windows 10 PC if that makes a difference.
I have a set of files which break up my program into sections, such as GUI, tooltips, procedures etc.
The GUI interface is my main program from which I want to source the other Tcl programs, all in the same directory.
Obviously I can use: cd C:/dir/dir.... and then just use source <file>
BUT, I'd like to be able to do this from whatever directory the files all happen to be in, so I need a generic way of "cd-ing" to the dir wherever it is.
I thought something like set x [pwd]
then... cd $x would work? Apparently not.
Windows 10 PC if that makes a difference.
TIA, Kev P.
Am 07.11.2022 um 14:38 schrieb snosniv:
I have a set of files which break up my program into sections, such as GUI, tooltips, procedures etc.
The GUI interface is my main program from which I want to source the other Tcl programs, all in the same directory.
Obviously I can use: cd C:/dir/dir.... and then just use source <file>
BUT, I'd like to be able to do this from whatever directory the files all happen to be in, so I need a generic way of "cd-ing" to the dir wherever it is.
I thought something like set x [pwd]
then... cd $x would work? Apparently not.
Windows 10 PC if that makes a difference.
TIA, Kev P.Dear Key,
the normal way to organize this is to use packages, namespaces and a pckIndex.tcl file.
Then, you put your folder with the pckIndex.tcl file into your auto_path search list.
There is a couple of explanation required here and Ashoks book may help
to get the basics.
What I do:
- my program has a main folder, which is relative to the start script.
- Say, your start script is somewhere, and all other folders are in
subfolder "lib".
- So add in the start script:
lappend auto_path [file join [file dirname [info script]] lib]
This command will automatically cause a scan for pckIndex.tcl files in
the given folder and all direct sub-folders.
The pckIndex.tcl file has an entry for each package in the same folder,
like this:
-pckIndex.tcl---
package ifneeded tools 1.0 [list source -encoding utf-8\
[file join $dir tools.tcl]]
-EOF-
A package "tools" with Version 1.0 is in the file tools.tcl
-tools.tcl- has the following
package provide tools 1.0
% program code
-EOF-
And the start script does this to load the package:
package require tools
It is common, that the package tools will reside in the namespace "tools".
If you have any other packages (3rd party), just put them also in your
lib folder and get them by package require.
Sorry, this does not answer your question directly,
Harald
Thanks Harald,
I'm only a "Dabbler" in Tcl, not a serious programmer (I'm a retired electronic hardware designer), so simple solutions suit me best!
I have a set of files which break up my program into sections, such as GUI, tooltips, procedures etc.
The GUI interface is my main program from which I want to source the other Tcl programs, all in the same directory.
Obviously I can use: cd C:/dir/dir.... and then just use source <file>
BUT, I'd like to be able to do this from whatever directory the files all happen to be in, so I need a generic way of "cd-ing" to the dir wherever it is.
I thought something like set x [pwd]
then... cd $x would work? Apparently not.
Windows 10 PC if that makes a difference.
TIA, Kev P.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 307 |
Nodes: | 16 (2 / 14) |
Uptime: | 56:20:17 |
Calls: | 6,914 |
Calls today: | 4 |
Files: | 12,379 |
Messages: | 5,430,690 |