Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adressing file on the local network

60 views
Skip to first unread message

Alexandru

unread,
Jun 29, 2018, 7:10:02 AM6/29/18
to
Hi,

on windows, file that are saved somewhere on the local network, can be adressed by a path such as \\name\name2\..\file.name

What is the way to do this in Tcl. How can I open a file given by such a path?

Thanks.
Alexandru

Arjen Markus

unread,
Jun 29, 2018, 7:37:01 AM6/29/18
to
It should be possible by specifying: //name/name2/../file.name

At least that worked fine on my system.

Regards,

Arjen

Alexandru

unread,
Jun 29, 2018, 7:40:53 AM6/29/18
to
Thanks for the quick answer. I tested this already as you write, but didn't worked. But I will try again, now that I know it should work.

Harald Oehlmann

unread,
Jun 29, 2018, 8:15:48 AM6/29/18
to
For me, both separators (\ and /) work:

(bin) 6 % file exist //rose/oehhar/test/testfile.txt
1
(bin) 7 % file exist {\\rose\oehhar\test\testfile.txt}
1

Take care with samba chares, where the latest patches by Sebres might be
helpful...

Enjoy,
Harald

Alexandru

unread,
Jun 29, 2018, 8:41:34 AM6/29/18
to
My bad: The problem was somwhere else in code and I prematurely assumed, that it's because of the leading double slash. Thanks for the help.

Ralf Fassel

unread,
Jul 2, 2018, 5:22:02 AM7/2/18
to
* Harald Oehlmann <wort...@yahoo.de>
| For me, both separators (\ and /) work:
>
| (bin) 6 % file exist //rose/oehhar/test/testfile.txt
| 1
| (bin) 7 % file exist {\\rose\oehhar\test\testfile.txt}
| 1

Most common mistake when using "\" is to forget that "\" is the TCL
escape character, so it either requires doubling

file exists \\\\rose\\oehhar\\test\\testfile.txt
=> 1

when used unquoted, or {}-quoting as in Harald's example #2.

Unfortunately some external apps insist on \ as path separator, so one
cannot blindly use "/" on Windows (which works "most-of-the-time").

R'

Gerhard Reithofer

unread,
Jul 2, 2018, 8:14:36 AM7/2/18
to
Hi,
confirmed.

My preferred method is to use always "/" except where I know that
"\\" is necessary (like in function "exec" where "native" paths maybe
required).

In such cases I use:
[file nativename $slashpath]

All path component handling, comparing and managing path names is done
by [file split $path] and [file join $path].
Relative path names are converted to absolute paths with [file normalize
$pat]
The only situation where I could not ignore the platform was the case
sensitivity of file names.

Then you shouldn't have to care about platform specific paths.
Windows:
% file split [file normalize Downloads]
C:/Users gerhard Downloads
is the same directory as
C:/Users gerhard downloads

Whereas on Unix:
/ home gerhard Downloads
and
/ home gerhard downloads
are different directories.

When comparing dir or file names platform code is unavoidable.
if {$::tcl_platform(platform) eq "windows} {
if {[string compare -nocase $path1 $path2] == 0} {
puts "Same path"
}
} else {
if {[string compare $path1 $path2] == 0} {
#or if {$path1 eq $path2} ...
puts "Same path"
}
}

Bye,
Gerhard

--
Gerhard Reithofer - Techn. EDV Reithofer - http://www.tech-edv.co.at
0 new messages