[R] check for new files in a given directory

William Dunlap wdunlap at tibco.com
Tue Jul 28 17:50:29 CEST 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Barry Rowlingson
> Sent: Tuesday, July 28, 2009 6:41 AM
> To: ted.harding at manchester.ac.uk
> Cc: r-help at r-project.org; Andreas Posch
> Subject: Re: [R] check for new files in a given directory
> 
> On Tue, Jul 28, 2009 at 12:36 PM, Ted
> Harding<Ted.Harding at manchester.ac.uk> wrote:
> 
> > However, this got me looking into '?list.files, and I see there
> > (R version 2.9.0 (2009-04-17)):
> >
> >  recursive: logical. Should the listing recurse into directories?
> >
> > But:
> >
> >  Directories are included only if 'recursive = FALSE'.
> >
> > Surely the latter is the wrong way round, and should be
> >
> >  Directories are included only if 'recursive = TRUE'.
> >
> 
>  by 'included' it means 'returned'. If you do 'recursive=TRUE' it
> scans recursively for files and only files. If you do
> "recursive=FALSE" it returns files and directories in the specified
> directory.
> 
> Makes it tricky to figure out a complete directory tree since empty
> directories won't appear at all if recursive=TRUE. You'd have to
> implement your own recursive search based on
> list.files(d,recursive=FALSE) and then testing for directoriness....
> 
>  Sucky, unless there's a better way...
> 
> Barry

S+'s dir() and list.files() functions have an extra argument called "type"
that let you say if you are interested in only "files" (non-directories) or
directories or want all directory entries listed in the output.  Its default value
is set to match the R behavior
  function(...,
    recursive=FALSE,
    type = if(recursive) c("files", "directories", "all") else c("all", "files", "directories"))
  {
       type <- match.arg(type)
       ...
  }
I put it in when I was looking for all directories named 'R' in a collection of
packages and bundles and I didn't want to use the platform-dependent
system() function.  Should this argument be added to R's dir() and
list.files() functions?

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com




More information about the R-help mailing list