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

Marc Schwartz marc_schwartz at comcast.net
Fri Jun 1 04:39:17 CEST 2007


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



More information about the R-help mailing list