From ripley at stats.ox.ac.uk  Fri Sep 23 19:19:40 2011
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri, 23 Sep 2011 18:19:40 +0100 (BST)
Subject: [Rd] should dir(all=TRUE) return "." and ".."?
In-Reply-To: <20092.47861.165002.499347@stat.math.ethz.ch>
References: <E66794E69CFDE04D9A70842786030B93074E30@PA-MBX04.na.tibco.com>
	<20092.47861.165002.499347@stat.math.ethz.ch>
Message-ID: <alpine.LFD.2.02.1109231815080.10207@gannet.stats.ox.ac.uk>

On Fri, 23 Sep 2011, Martin Maechler wrote:

>>>>>> William Dunlap <wdunlap at tibco.com>
>>>>>>     on Fri, 23 Sep 2011 15:49:43 +0000 writes:
>
>    > dir(all=TRUE) returns the file names "." and ".."  while
>    > dir(recursive=TRUE, all=TRUE, include.dirs=TRUE) does not.
>    > I always filter out the "." and ".." entries and was
>    > wondering if anyone would mind if dir(all=TRUE) just
>    > omitted them?  It might make recursive file operations
>    > like cleaning out a directory safer, as
>    > unlink(recursive=TRUE, dir(all=TRUE, "dirToClean")) might
>    > start attacking dirToClean/.., then dirToClean/../..,
>    > etc., until your disk is empty.
>
> :-)
>
> Thank you, Bill.
> I agree that there is a problem.  It seems wrong to me that
>
>   dir(all.files=TRUE, recursive=TRUE, include.dirs=TRUE)
>
> *omits* the (symbolic) directories  '.' and '..'  when simple
>
>   dir(all.files=TRUE)
>
> includes them.

It was intentional.  The authors of that part wanted it that way, the 
original author of list.files (aka dir) wanted this the way it was 
before include.dirs was added.

> However, from a strict description (of the argument names, and
> also the help file) I would have expected that both would *include*
> rather than omit them.
> But then --the scenario abov, and also more general
> reasoning -- would rather suggest to follow your proposal.

Someone would need to check for back-compatibility though: 
list.files() has been around for a long time.

There are lots of odder things about list.files(), for example that it 
lists directories with recursive=FALSE and not with recursive=TRUE. 
So is a directory a file or not?

> Martin
>
>
>    >> dir.create(tdir <- tempfile("tdir"))
>    >> file.create(file.path(tdir, c(".dotFile", "noDotFile")))
>    >   [1] TRUE TRUE
>    >> dir.create(file.path(tdir, ".dotDir"))
>    >> file.create(file.path(tdir, ".dotDir",
>    >> c("noDotFileInDotDir", ".dotFileInDotDir")))
>    >   [1] TRUE TRUE
>    >> dir(tdir, all=TRUE) # omit "." and ".." here?
>    >   [1] "."  ".."  ".dotDir" ".dotFile" [5] "noDotFile"
>    >> dir(tdir, all=TRUE, recursive=TRUE, include.dirs=TRUE)
>    >   [1] ".dotDir" ".dotDir/.dotFileInDotDir" [3]
>    > ".dotDir/noDotFileInDotDir" ".dotFile" [5] "noDotFile"
>
>    > Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] should dir(all=TRUE) return "." and ".."?
Prof Brian Ripley