name of working directory?

Started by Sammo, December 20, 2003, 08:05:48 AM

Previous topic - Next topic

Sammo

Can I determine the name of the current working directory?  Ideally the full path (including drive letter on Windows) would be returned.  How about (wd) for 'working directory' or (path-info ".") in the spirit of file-info which could also be used like this (path-info "../..") to get the full path info for the grandparent of the current working directory.

Lutz

#1
The first element in (main-args) will contain the full path-file name of the newLISP executable, this is also (at least normally at startup) the current working directory.



When you run newLISP without the tk frontend you also can try the following:



(exec "cd") => ("C:\Documents and Settings\Lutz") ;; Win32



(exec "pwd") => ("/usr/home/nuevatec/ftp/newlisp") ;; on Linux, UNIX



Which will be more reliable than the first suggestion, but doesn't work inside the newLISP-tk frontend. There should also be some Win32 call which you could import.



Lutz

Sammo

#2
;;  cwd
;;  return the current working directory (Windows)
;;
;;  From http://www.secunia.com/advisories/8037/, we learn that in the
;;  Windows API the maximum length for a path is 260 characters structured
;;  as follows: Drive letter, colon, backslash, components separated by
;;  backslashes and a null-terminating character (eg. "D:<256 chars>NUL"),
;;  which restricts the path on a drive to 256 characters.
;;
(import "kernel32.dll" "GetCurrentDirectoryA")
(define (cwd , buff bufflen)
    (setq bufflen 260 buff (allocate bufflen))
    (GetCurrentDirectoryA bufflen buff)
    (string buff))

Lutz

#3
I will start a file with all those usefull little routines.



BTW instead of (string buff) use (trim buff), it also will strip away the trailing spaces, but is about 4 times faster in this situation.





Lutz