Top Document: FAQ: Lisp Frequently Asked Questions 2/7 [Monthly posting] Previous Document: [2-18] What reader macro characters are used in major Lisp systems? Next Document: [2-20] What is a "Lisp Machine" (LISPM)? See reader questions & answers on this topic! - Help others by sharing your knowledge program? Is there any way to create a directory? There is no portable way in Common Lisp of determining whether a file is a directory or not. Calling DIRECTORY on the pathname will not always work, since the directory could be empty. For UNIX systems (defun DIRECTORY-P (pathname) (probe-file (concatenate 'string pathname "/."))) seems to work fairly reliably. (If "foo" is a directory, then "foo/." will be a valid filename; if not, it will return NIL.) This won't, of course, work on the Macintosh, or on other operating systems (e.g., MVS, CMS, ITS). On the Macintosh, use DIRECTORYP. Moreover, some operating systems may not support the concept of directories, or even of a file system. For example, recent work on object-oriented technology considers files to be collections of objects. Each type of collection defines a set of methods for reading and writing the objects "stored" in the collection. There's no standard function for finding the current directory from within a Lisp program, since not all Lisp environments have the concept of a current directory. Here are the commands from some Lisp implementations: Lucid: WORKING-DIRECTORY (which is also SETFable) PWD and CD also work Allegro: CURRENT-DIRECTORY (use excl:chdir to change it) CMU CL: DEFAULT-DIRECTORY LispWorks: LW:*CURRENT-WORKING-DIRECTORY* (use LW:CHANGE-DIRECTORY to change it) Allegro also uses the variable *default-pathname-defaults* to resolve relative pathnames, maintaining it as the current working directory. So evaluating (truename "./") in Allegro (and on certain other systems) will return a pathname for the current directory. Likewise, in some VMS systems evaluating (truename "[]") will return a pathname for the current directory. There is no portable way of creating a new directory from within a Lisp program. User Contributions:Top Document: FAQ: Lisp Frequently Asked Questions 2/7 [Monthly posting] Previous Document: [2-18] What reader macro characters are used in major Lisp systems? Next Document: [2-20] What is a "Lisp Machine" (LISPM)? Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page [ Usenet FAQs | Web FAQs | Documents | RFC Index ] Send corrections/additions to the FAQ Maintainer: ai+lisp-faq@cs.cmu.edu
Last Update March 27 2014 @ 02:11 PM
|
Comment about this article, ask questions, or add new information about this topic: