name of working directory?

For the Compleat Fan
Locked
Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

name of working directory?

Post by 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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

Post by Sammo »

Code: Select all

;;  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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Locked