>>>>> William Dunlap <wdun...@tibco.com> >>>>> on Tue, 28 Jul 2009 08:50:29 -0700 writes:
>> -----Original Message----- >> From: r-help-boun...@r-project.org >> [mailto:r-help-boun...@r-project.org] On Behalf Of Barry Rowlingson >> Sent: Tuesday, July 28, 2009 6:41 AM >> To: ted.hard...@manchester.ac.uk >> Cc: r-help@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.hard...@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? Yes, I think it "should" -- exactly because I also like to work without system() here. I will not implement it myself though, as I nowadays build R only for Linux {or intermittently, one flavor of Solaris}, and from recent "experience" with file.access() {not working reliably on some Windows-version x file-system combination}, this doesn't seem easy to get right. I think R core would be very grateful for patches (particularly if from someone as qualfied as you). Martin Maechler, ETH Zurich > Bill Dunlap > TIBCO Software Inc - Spotfire Division > wdunlap tibco.com ______________________________________________ R-help@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.