Iris
Iris

Reputation: 1162

R: list files based on pattern

I want to list all files that start with "aT_" and have the extention ".tif" (e.g aT_123456_1x1_abcdef.tif):

files<- list.files(pattern="^aT_")
files<- list.files(pattern="\\.tif$") 

How can I combine the patterns? Is there a wildcard for any kind of symbol: e.g 0-9,a-z, A-Z, _? Something like files<- list.files(pattern="^aT_[any kind of symbol]\\.tif$")?

Upvotes: 8

Views: 13369

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174696

Use .* for matching any kind of character except line breaks.

files<- list.files(pattern="^aT_.*\\.tif$")

or

files<- list.files(pattern="^aT_\\w*\\.tif$")

Upvotes: 17

Related Questions