Tcl slash backslash

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

Reply to
Udo
Loading thread data ...

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 to
Phil Hays

Indeed it does.

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
 Click to see the full signature
Reply to
Jonathan Bromley

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.