Page 1 of 1
(directory?) inconsistency
Posted: Fri Dec 14, 2007 1:52 pm
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
Posted: Fri Dec 14, 2007 2:20 pm
by newdep
yes that correct ;-)
>(directory? "c:/")
true
>(directory? "c:/\\")
true
>(directory? "/")
true
Posted: Fri Dec 14, 2007 4:08 pm
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?
Posted: Fri Dec 14, 2007 4:34 pm
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.
Posted: Fri Dec 14, 2007 5:00 pm
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....
Posted: Fri Dec 14, 2007 5:05 pm
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.. ;-)
Posted: Fri Dec 14, 2007 5:08 pm
by pjot
Thanks, but unfortunately it is not that easy in my program :-(
...which is my contribution for the contest, by the way ;-)
Posted: Fri Dec 14, 2007 5:10 pm
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/"