(directory?) inconsistency

Started by pjot, December 14, 2007, 05:52:24 AM

Previous topic - Next topic

pjot

Hi,



In Linux, this code works:
Quote
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:
Quote
newLISP v.9.2.0 on Win32, execute 'newlisp -h' for more info.



> (directory? "C:\Temp")

true

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

nil




Regards

Peter

newdep

#1
yes that correct ;-)



>(directory? "c:/")

true

>(directory? "c:/\")

true

>(directory? "/")

true
-- (define? (Cornflakes))

pjot

#2
Your examples do not use actual directories...


Quote
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

#3
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

#4
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

#5
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

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



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

newdep

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





PS: this works too



> (join (parse {c:owidontlikewindows} {}) "/")

"c:/ow/i/dont/like/windows/"
-- (define? (Cornflakes))