For Programmers: Free Programming Magazines  


Home > Archive > Tcl > May 2004 > Is this behavior of [file exists] a bug or not?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Is this behavior of [file exists] a bug or not?
David Gravereaux

2004-05-18, 11:31 pm

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\WINNT\system32>tclsh85
% info patch
8.5a2
% cd [file dirname [info name]]
% file exists tcl85.dll
1
% file exists tcl85.dll.
1
% file exists tcl85.dll.....
1
% file readable tcl85.dll.....
1
% file extension tcl85.dll.....
..
% file extension tcl85.dll
..dll
%

This oddity is causing a problem for me if the user enters a filename and
adds extra periods at the end. [file exist] and [file readable] return
true, but then [file extension] returns bad data so when I do different
behavior for the file extension my logic gets it all wrong.

I found that [file normalize] can give me the actual filename, so this
oddity does have a work-around.

Is this a bug?
--
David Gravereaux <davygrvy@pobox.com>
[species: human; planet: earth,milkyway(western spiral arm),alpha sector]
Wojciech Kocjan

2004-05-19, 3:31 am

David Gravereaux wrote:
> This oddity is causing a problem for me if the user enters a filename and
> adds extra periods at the end. [file exist] and [file readable] return
> true, but then [file extension] returns bad data so when I do different
> behavior for the file extension my logic gets it all wrong.


This is the way Windows works.

% set fh [open a.b.c.... w]
file8ff9a8
% close $fh
% file exists a.b.c

This one actually creates "a.b.c" and not "a.b.c....". Heck, once you'll
try to understand Windows' ways of filename sorting, you'll understand
that it's veeery strange (it sorts by name and then extension, not
simply by entire filename).

--
WK

Ralf Fassel

2004-05-19, 4:31 am

* David Gravereaux <davygrvy@pobox.com>
| Microsoft Windows 2000 [Version 5.00.2195]
--<snip-snip>--
| Is this a bug?

Yes :-)

But more seriously, Windows discards trailing dots when handling file
and directory names.

% close [open {bar.} w]
% exec ls -l
-rw-r--r-- 1 ralf Kein 0 May 19 09:32 bar

This is especially a problem when dealing with files on a Unix file
server, where those filenames are legal.

% exec ls -l
-rwxr-xr-x 1 ralf Kein 70 May 19 09:28 foo.
% glob *
no files matched glob pattern "*"
% file exists foo.
0
% open foo. r
file100d5d58
% read file100d5d58
#!/bin/sh --
# foo.
# End of file
%

So the file does not exist, but I can open and read it. I also
observed the opposite effect: the files exists, but trying to open it
failed with `does not exist'.

R'
David Gravereaux

2004-05-19, 4:33 pm

Ralf Fassel <ralfixx@gmx.de> wrote:

>So the file does not exist, but I can open and read it. I also
>observed the opposite effect: the files exists, but trying to open it
>failed with `does not exist'.


;) I wonder if there is any way to even-out these differences?
--
David Gravereaux <davygrvy@pobox.com>
[species: human; planet: earth,milkyway(western spiral arm),alpha sector]
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com