Jason Rupert
2009-Jun-23 19:06 UTC
[R] list.files(getwd()) and list.files(getwd(), full.names=TRUE) appear to return directory names
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
Henrique Dallazuanna
2009-Jun-23 19:14 UTC
[R] list.files(getwd()) and list.files(getwd(), full.names=TRUE) appear to return directory names
Try this: row.names(subset(file.info(list.files()), !isdir)) On Tue, Jun 23, 2009 at 4:06 PM, Jason Rupert <jasonkrupert@yahoo.com>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@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Duncan Murdoch
2009-Jun-23 19:16 UTC
[R] list.files(getwd()) and list.files(getwd(), full.names=TRUE) appear to return directory names
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
Romain Francois
2009-Jun-23 19:20 UTC
[R] list.files(getwd()) and list.files(getwd(), full.names=TRUE) appear to return directory names
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. > > Jasonyou can filter the result, as in: R> Filter( function(x) !file.info(x)$isdir, list.files("/tmp", full = T ) ) Romain -- Romain Francois Independent R Consultant +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr