[R] how to get list of files within a particular local file folder

Bretschneider SIG-R bretschr at xs4all.nl
Wed Jul 4 18:31:02 CEST 2012


Dear Ajay Ohri,

Re:

> Dear List,
> 
> Say I can use getwd() and setwd() to change my working directory. How can I
> read in all the files within that directory using command line (like a ls()
> but for the path specified)
> 

I use this function,

#  functions
getFolder <- function(pat)
	{
	txt=file.choose()
	#cat(txt,'\n')
	pos=0
	fname=basename(txt) 
	#cat(paste("\nFilename found is: ",fname,'\n'))
	foln = dirname(txt)
	cat(paste("\nFolder name found is: ",foln,'\n'))
	drtext=dir(foln, pattern=pat, full.names = TRUE)
	#cat('\n\n\n\n') 
	return(drtext)
	}


Best,

Franklin

Dr F. Bretschneider
Dept of Biology
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands



More information about the R-help mailing list