Re: [R] find directories

From: mel <mel_at_altk.com>
Date: Wed, 23 Apr 2008 11:25:19 +0200

Prof Brian Ripley a écrit :
> On Wed, 23 Apr 2008, mel wrote:
>

>> Hello,
>> Function dir() is very useful for finding files.
>> However, is there a analog function for finding directories
>> based eg on a pattern ?

>
> No.
>
>> Apologies if I've missed something obvious.

>
> list.dirs <- function(...)
> {
> x <- dir(...)
> x[file_test("-d", x)]
> }

Thanks for the fast answer Prof Ripley.

In fact, I was using (on a tree of directories of depth 4) x <- dir(..., recursive=TRUE)
and didn't notice that the results from
dir(...) is not included in dir(..., recursive=TRUE)

If I'm not wrong, x <- dir(..., recursive=TRUE) seems to return the findable *files only* in the tree. While x <- dir(...)
returns the *files and the directories* present at the top level of the tree.

The directories I'm searching are unfortunately not at the top level, But, in my special case, I'm lucky enough that a simple trick allows to identify the directories.

Thanks
Vincent



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 23 Apr 2008 - 09:34:36 GMT

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 Wed 23 Apr 2008 - 10:30:31 GMT.

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

list of date sections of archive