(directory?) inconsistency

For the Compleat Fan
Locked
pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

(directory?) inconsistency

Post by pjot »

Hi,

In Linux, this code works:
newLISP v.9.2.0 on Linux, execute 'newlisp -h' for more info.

> (directory? "/tmp")
true
> (directory? "/tmp/")
true

However, in Win32 we see this:
newLISP v.9.2.0 on Win32, execute 'newlisp -h' for more info.

> (directory? "C:\\Temp")
true
> (directory? "C:\\Temp\\")
nil

Regards
Peter

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

yes that correct ;-)

>(directory? "c:/")
true
>(directory? "c:/\\")
true
>(directory? "/")
true
-- (define? (Cornflakes))

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Your examples do not use actual directories...
c:\Scripts>newlisp
newLISP v.9.2.0 on Win32, execute 'newlisp -h' for more info.

> (directory? "c:/")
true
> (directory? "c:/temp")
true
> (directory? "c:/temp/")
nil
>
Why?

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

I still dont see the problem?

The manualy says ->

On Win32 systems, there should be no trailing slash character after the directory name, but the drive letter must be followed by a colon and a forward slash (:/). On Linux/UNIX systems, a trailing slash after the directory name will not cause problems.
-- (define? (Cornflakes))

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Oops I overlooked that... creating my sources in Linux, and after that running in Windows, but never looking into the manual again because it is working in Linux, right? ;-)

Anyway, this situation causes the code to be less portable. So in a Win32 situation, you always have to explicitly add a "/" between the directoryname and the filename if you want to concatenate them. In Unix this is not necessary.

<Sigh>

In the end it has something to do with the C API of course, which is different in Win32 compared to Unix, but from user-experience-point-of-view, it is a little bit uncomfortable... but I'll if-then-else around it....

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Yes your right , it feels unconfortable but I use as as a simple solution

(if (ends-with directory "/") (chop directory))

which works on linux and windows.. ;-)
-- (define? (Cornflakes))

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Thanks, but unfortunately it is not that easy in my program :-(

...which is my contribution for the contest, by the way ;-)

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Try harder ;-) We need to your contribution ;-)


PS: this works too

> (join (parse {c:\ow\i\dont\like\windows\} {\}) "/")
"c:/ow/i/dont/like/windows/"
-- (define? (Cornflakes))

Locked