Re: [R] scan a directory and then make a string vector consisting of file names

From: Marc Schwartz <marc_schwartz_at_comcast.net>
Date: Thu, 31 May 2007 21:39:17 -0500

On Thu, 2007-05-31 at 21:18 -0500, Taka Matzmoto wrote:
> Dear R-users,
>
> I am looking for a way to scan a directory and then make a string vector
> consisting of the file names in the directory.
>
> For example, under c:\temp\
> there are 4 files
> a.txt, b.txt, c.txt, and d.txt
>
> I would like to have a string vector
> c("a.txt","b.txt","c.txt","d.txt")
>
> How do I do that?
>
> Thanks
>
> Taka,

See ?list.files

For example:

  list.files("c:/temp", pattern = "\\.txt")

Note the use of the forward slash in the 'path' argument. See R Windows FAQ: http://cran.r-project.org/bin/windows/base/rw-FAQ.html#R-can_0027t-find-my-file

HTH, Marc Schwartz



R-help_at_stat.math.ethz.ch 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 Fri 01 Jun 2007 - 02:48:44 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 Fri 01 Jun 2007 - 06:31:36 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.