2

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?

2
  • 1
    Is it actual X or could it be any alpha character? Commented Nov 7, 2013 at 2:43
  • 1
    sorry, I should be more specific. XXXX here means characters that might be in other language(simplified Chinese). Commented Nov 7, 2013 at 2:50

2 Answers 2

10

Try this

list.files(path="./yourdir",pattern="[[:digit:]]{8}.*\\.pdf") 
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, can I specify the 8 digit number here? Say, I want the prefix to be exact '20131106'
yes, the pattern would match any 8 digit number followed by 0 or more arbitrary characters, and extension .pdf. Replace it with "20131106.*\\.pdf" to match only files starting with 20131106. Check ?regex for more info on regular expressions.
3

You can use regex.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.