[R] list.files(getwd()) and list.files(getwd(), full.names=TRUE) appear to return directory names

Duncan Murdoch murdoch at stats.uwo.ca
Tue Jun 23 21:16:37 CEST 2009


On 6/23/2009 3:06 PM, Jason Rupert wrote:
> Is there any way to make list.files(getwd()) or list.files(getwd(),full.names=TRUE) stop returning directories? 
> 
> Right now both appear to return both file names and folders within the location.  
> 
> I would like for it only to return file names and not folders. 
> 
> I am using this on Windows with R version 2.9.0 (2009-04-17). 
> 
> Thank you again for all your help and any feedback.  
> 
> Jason
> 
> ______________________________________________
> 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.



No, but file.info() can tell you whether a particular result is a 
directory or not.  So you can get just files using

everything <- list.files( <your selection here>, full.names=TRUE)
files <- everything[ !file.info(everything)$isdir ]

Duncan Murdoch




More information about the R-help mailing list