On Fri, 04 May 2007 03:20:18 GMT, Phil Hays <invalid@dont.spam> wrote:
>Udo wrote:
>> I'm using XP and paths are separated with backslashes. But Tcl uses
>> slashes.
Indeed it does.
>Yes, I suggest you use "file join". This standard Tcl command creates an
>OS correct path for any OS.
Not quite. [file join] constructs Tcl-style (/-separated)
pathnames from components. The really nice thing about [file join]
is that it's very tolerant of all sorts of input. But it does NOT
fix-up the backslashes for Windows.
For example:
% file join /home work play
/home/work/play
% file join /home/ work/ play/
/home/work/play
% file join /home// work play///
/home/work/play
These /-style names work just fine within Tcl, and as
arguments to any Tcl-aware program. But of course they
won't work as input to an ordinary Windows program.
If you really, really need a Win32 filename (for example,
because you're trying to set an environment variable,
or any other situation where the filename will be
processed by a non-Tcl-aware program) you can always
use [file nativename]:
% file nativename /home/work
\home\work
(of course, on *nix it would give you a /-separated
name).
Be very careful, though, because backslash has special
meaning to Tcl. if you type a backslash-separated
name interactively, you'll need to double-up the
backslashes:
% file nativename \home\work
homework
% file nativename \\home\\work
\home\work
or alternatively, enclose the offending string in
curly brackets:
% file nativename {\home\work}
\home\work
Generally, as long as you are working entirely within the
Tcl environment the best advice is...
- in your own scripts and commands, use /-style names
- if you get a \-style name from somewhere else (e.g. an
environment variable, or from the contents of another file)
then you can use it, but DON'T type such names interactively
- if you need to generate a \-style name for use by non-Tcl
programs or to put into Win environment variables, use
Tcl /-style names but use [file nativename] to do a final
conversion to \-style before you make external use of the name.
hth
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
Reply by Phil Hays●May 4, 20072007-05-04
Udo wrote:
> Hello all,
>
> I'm using XP and paths are separated with backslashes. But Tcl uses
> slashes. How do you handle that, are there any tricks? I'm working
> mostly with ISE 9.1, but looking for a common solution.
Yes, I suggest you use "file join". This standard Tcl command creates an
OS correct path for any OS.
Some examples:
To see what it does
puts [file join foobar doodoo try.this]
To make a "bld" directory at the same level
file mkdir [file join ".." bld]
To change default to this directory
cd [file join ".." bld]
To add a few files to a Xilinx project from a source directory at the same
level
xfile add [".." src foobar.vhd]
xfile add ["..] src snafu.v]
--
Phil Hays
Reply by Udo●May 3, 20072007-05-03
Hello all,
I'm using XP and paths are separated with backslashes. But Tcl uses
slashes.
How do you handle that, are there any tricks? I'm working mostly with
ISE 9.1,
but looking for a common solution.
Thanks and greetings
Udo