Re: [Rd] should dir(all=TRUE) return "." and ".."?

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Fri, 23 Sep 2011 18:59:33 +0200

>>>>> 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.

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.

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 Received on Fri 23 Sep 2011 - 17:01:41 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 23 Sep 2011 - 18:10:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive