In article <6uodup$ka...@nnrp1.dejanews.com>, <seligskiy....@ispi.net> wrote: >Can anybody help me to determin what names received by "directory" function >are the names of "subdirectories", and what ones are names of "files"?
There's no portable way to do this directly. An indirect way is to construct a new pathname by appending the name to the original path, and then try to list that subdirectory. If this succeeds then the name referred to a subdirectory or a symbolic link pointing to a directory; if it fails then either it doesn't refer to a subdirectory or you don't have access to list it.
-- Barry Margolin, bar...@bbnplanet.com GTE Internetworking, Powered by BBN, Burlington, MA *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
In article <CwRP1.15$94.258...@burlma1-snr1.gtei.net>, Barry Margolin
<bar...@bbnplanet.com> wrote: > In article <6uodup$ka...@nnrp1.dejanews.com>, <seligskiy....@ispi.net> wrote: > >Can anybody help me to determin what names received by "directory" function > >are the names of "subdirectories", and what ones are names of "files"?
> There's no portable way to do this directly.
Wouldn't it be nice to have something like that?
MCL adds some functionality:
DIRECTORY pathname &key :directories :files :directory-pathnames :test :resolve-aliases [Function] returns a list of the truenames of all files or folders that match pathname, using * as a wildcard character. directory must accept logical pathnames but does not return them.
Example:
(directory "ccl:examples;*" :directories t :files nil)
Barry Margolin <bar...@bbnplanet.com> writes: > There's no portable way to do this directly. An indirect way is to > construct a new pathname by appending the name to the original path, and > then try to list that subdirectory. If this succeeds then the name > referred to a subdirectory or a symbolic link pointing to a directory; if > it fails then either it doesn't refer to a subdirectory or you don't have > access to list it.
I was always under the impression that a null value for pathname-name would indicate a directory. How is that unreliable?
< < Hi, everyone! < < Can anybody help me to determin what names received by "directory" function < are the names of "subdirectories", and what ones are names of "files"? < < Thank you.
It depends on which lisp implementation you're using. For acl and lispworks you can use `file-directory-p'. You may get lucky with (apropos 'directory).
The faq mentions something like the following as a last resort.
>> There's no portable way to do this directly. An indirect way is to >> construct a new pathname by appending the name to the original path, and >> then try to list that subdirectory. If this succeeds then the name >> referred to a subdirectory or a symbolic link pointing to a directory; if >> it fails then either it doesn't refer to a subdirectory or you don't have >> access to list it.
>I was always under the impression that a null value for pathname-name would >indicate a directory. How is that unreliable?
PATHNAME-NAME is essentially just a slot accessor, it returns whatever was specified in the call to MAKE-PATHNAME. Consider my home directory /users/barmar. I can do (make-pathname :directory '("users" "barmar")) or (make-pathname :directory '("users") :name "barmar"). In the first case, PATHNAME-NAME will return return NIL, in the second it will return "barmar".
I expect that in most implementations, (directory "/users/*") will return entries like the second case.
-- Barry Margolin, bar...@bbnplanet.com GTE Internetworking, Powered by BBN, Burlington, MA *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
> In article <CwRP1.15$94.258...@burlma1-snr1.gtei.net>, Barry Margolin > <bar...@bbnplanet.com> wrote:
> > In article <6uodup$ka...@nnrp1.dejanews.com>, <seligskiy....@ispi.net> wrote: > > >Can anybody help me to determin what names received by "directory" function > > >are the names of "subdirectories", and what ones are names of "files"?
> > There's no portable way to do this directly.
> Wouldn't it be nice to have something like that?
> MCL adds some functionality:
> DIRECTORY pathname &key :directories :files > :directory-pathnames :test :resolve-aliases > [Function] > returns a list of the truenames of all files or folders that match > pathname, using * as a wildcard character. directory must accept > logical pathnames but does not return them.
> Example:
> (directory "ccl:examples;*" > :directories t > :files nil)
In article <CwRP1.15$94.258...@burlma1-snr1.gtei.net>, Barry Margolin <bar...@bbnplanet.com> wrote:
> In article <6uodup$ka...@nnrp1.dejanews.com>, <seligskiy....@ispi.net> wrote: > >Can anybody help me to determin what names received by "directory" function > >are the names of "subdirectories", and what ones are names of "files"?
> There's no portable way to do this directly. An indirect way is to > construct a new pathname by appending the name to the original path, and > then try to list that subdirectory. If this succeeds then the name > referred to a subdirectory or a symbolic link pointing to a directory; if > it fails then either it doesn't refer to a subdirectory or you don't have > access to list it.
Yes, but "directory" function will return "nil" if folder is empty. As a file.
-- Stas Selitskiy
-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
* seligskiy....@ispi.net | Unfortunately, acl I use does not maintain :directory and :file key | parameters.
the function EXCL:ARGLIST reports the argument list of a function, as does the Emacs/Lisp Interface function FI:LISP-ARGLIST, ordinarily bound to C-c a and M-A in Lisp mode or in a Listener.
> > There's no portable way to do this directly. An indirect way is to > > construct a new pathname by appending the name to the original path, and > > then try to list that subdirectory. If this succeeds then the name > > referred to a subdirectory or a symbolic link pointing to a directory; if > > it fails then either it doesn't refer to a subdirectory or you don't have > > access to list it.
> I was always under the impression that a null value for pathname-name would > indicate a directory. How is that unreliable?
> Sunil
Eclipse takes the following approach, from http://www.elwood.com/eclipse/path.htm#truenames I think it's "the right thing", but then, I'm pretty biased! (If people agree that this is the right thing, they might consider talking to their vendor.) Note that ANSI requires DIRECTORY to return truenames.
------ As defined by ANSI, a truename is a canonicalized pathname in which wildcards and mnemonic version numbers have been resolved, logical host translations have been resolved, and, in general, multiple ways of referring to the same file in the file system have been resolved to the most canonical form.
There are two Eclipse-specific aspects of this last issue that are of note:
1.In some situations, some file systems, such as Unix, allow namestrings that refer to directories to be specified with or without the trailing directory separator (eg. "/dir/subdir" or "/dir/subdir/"). In other words, something that looks like a filename might refer to a file or to a directory.
In Eclipse, the truename of a directory is always canonicalized such that the namestring prints as a directory (eg. "/dir/subdir/"), and the PATHNAME-NAME, PATHNAME-TYPE and PATHNAME-VERSION are all :UNSPECIFIC.
2.Some file systems allow files to be symbolically linked to other files or directories. In general, Eclipse truenames resolve such links to their ultimate file or directory destination. However, DIRECTORY allows the programmer to specify whether such symbolic links are followed once, completely, or not at all.
----- A problem with using nil instead of :unspecific is that it isn't really cannonicalized. If both are acceptable, then you don't really know what to expect. Besides, if you want to, for example, use PROBE-FILE to see if a directory exists, you don't want it merging in the defaults from *defualt-pathname-defaults*. Thus, if the system went around returning truenames with null-components, you might find that some later action with those TRUENAMES merged in different values and returned results for a DIFFERENT file.
Note that the "append / hack" isn't really portable. It assumes #\/ as the directory separator, and it assumes that neither the Lisp implementation nor the file system support DWIMing of pathnames. (For example, in Emacs, you can specify a filename as /foo/bar//tmp, and get back just /tmp.)
>It works! >It's the only real portable way. >Thank you!
portable? hmm... you could try to use
(defun dir-p (path) (probe-file (concatenate 'string path ;; will work on some filesystems, on those which ;; use "." as file-alias for the actual dir ("self") ;; and accept "/" as path delimiter (unix, winnt) "/.")))
or even (defun dir-p (path) (probe-file (concatenate 'string path ;; will work on less filesystems, ;; on these which support the NUL device as file "/NUL")))
but none of those are portable at all. they will only work on winnt and on various unix variants, but not on DOS+Win3.x (needs "\\"), mac (needs ":"), vms "[]", or any other non-unix os as stated in the FAQ. i cannot really remember now what win95 and win98 do with the "/". nt at least accepts it as valid path-delim.
most OS also support a file-attribute which tells you if this file is a directory. i would use this. something like a posix stat. this would fit better to OS which treat files as objects and dirs as collection of objects and should therefore be more portable. file-attribute <==> slot
this is really a mess. make-pathname seems to accept only files but no directories, though CLHS would imply it. so (probe-file (make-pathname :directory path :name ".")) or similar attempts will fail --- Reini Urban http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
< >In article <m2pvcfwii5....@KludgeUnix.com>, < > Steve Gonedes <jgone...@worldnet.att.net> wrote: < > < >> The faq mentions something like the following as a last resort. < >> < >> (defun dir-p (path) < >> (probe-file (concatenate 'string path "./"))) ^^ -- should say "/."
I was thinking that a namestring or path with a trailing slash would be used, such as "/usr/local/", and since I'm used to having the slash be used to distinguish a file from a directory I included it - I probably should have written "/./", but I hate pathnames that have two trailing slashes (I get this in my C and shell programs all too often - drives me nuts because it seems so kludgy). A better way would be to have an optional argument but the optimal solution would be a built in method I suppose.
I guess it depends on the tools and problem you have to deal with. Maybe there should be some constant which serves as the path seperator? What if there are no pathnames? Maybe :unspecified? I dunno, it's a tough issue.
< this is really a mess. make-pathname seems to accept only files but no < directories, though CLHS would imply it. < so (probe-file (make-pathname :directory path :name ".")) or similar < attempts will fail
I'll agree with you to some degree, but I'm glad that there is a method for dealing with something as common as pathnames. It's better to have a starting point than to ignore the issue altogether, IMHO. There's always logical pathnames (which can work to some degree).
The real difficulty I think is the lack of a common distinction amoung _every_ operating system for a directory, file, and most importantly it's type (I ignore versions because their lack of on my machine gets me so angry). In unix with `~/emacs/.saves', would we call `.saves' a nameless file with no type? Or is it actually a directory with no name, hence `~/emacs/.saves/'? There is no concept of `type' to be found within the unix universe. Should filenames be limited to eight characters long to accommodate windows95 (which altogether ignores the issue of filenames, IMHO) and DOS?
To me the biggest problems I have when writing programs is interfacing with the unix `knowledge stores'. No matter what language, storing things in a file/program-dependant manner is just not a good idea. Ideas like using an invisible marker (such as a tab versus a space) for a `seperator of information' makes me think of unix as a database of bad ideas.
In spite of all this, cl has given me the ability to describe a file by it's type. It's not perfect, just very convenient.
Steve Gonedes <jgone...@worldnet.att.net> wrote: >The real difficulty I think is the lack of a common distinction amoung >_every_ operating system for a directory, file, and most importantly >it's type (I ignore versions because their lack of on my machine gets >me so angry). In unix with `~/emacs/.saves', would we call `.saves' a >nameless file with no type? Or is it actually a directory with no >name, hence `~/emacs/.saves/'? There is no concept of `type' to be >found within the unix universe.
.saves has the filename ".saves" and an empty type. (cmucl docs) but this implementation defined as i understand it. translation rules for dumber filesystems are not in CLHS. having had specified some of these rules (e.g. for unix, win32 and dos) would have made life easier.
a simple example such as below would be fine: ;;unix (pathname-name ".foo") => ".foo" (pathname-name ".foo.l") => ".foo"