user2854008
user2854008

Reputation: 1221

Find all file names that match a pattern

I am trying to find a way to list all file names in a folder that matches this pattern :

20131106XXXXX.pdf 

The prefix is the date, and the content and length of XXXX vary across files, and I only care about pdf files.

Anyone could advise a way to do this?

Upvotes: 2

Views: 8308

Answers (2)

CHP
CHP

Reputation: 17189

You can use regex.

files <- dir(pattern="^[0-9]{8}.*\\.pdf")

Upvotes: 3

ndr
ndr

Reputation: 1437

Try this

list.files(path="./yourdir",pattern="[[:digit:]]{8}.*\\.pdf") 

Upvotes: 10

Related Questions