Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list only certain files in R?

Tags:

r

I have thousands of different files (having the same extension .img) in a folder called data. If I use this :

 dir<- list.files ("C:\\Users\\data", "*.img", full.names = TRUE)

It will list all files I have in the folder data.

What I need is just to list the files named as:

 File_yyyymmdd_data.img     (in which yyyymmdd varies for 10 years)

Any idea or hint is appreciated!

like image 927
sacvf Avatar asked Sep 20 '25 05:09

sacvf


1 Answers

try this

files.new = list.files(directory.path, recursive = TRUE, pattern=".img")

Where, "directory.path" is the path to the directory containing files you need to read


edited

to be more appropriate

files.new = list.files(directory.path, recursive = TRUE, pattern="File_[0-9]{8}_data[.]img$")
like image 108
Veerendra Gadekar Avatar answered Sep 22 '25 19:09

Veerendra Gadekar