0

I'm trying to get a list of subdirectories from a path. These subdirectories have a time pattern month\day\hour, i.e. 03\21\11. I naively used the following:

 list.files("path",pattern="[0-9]\[0-9]\[0-9]", recursive = TRUE, include.dirs = TRUE)

But it doesn't work. How to code for the digitdigit\digitdigit\digitdigit pattern here? Thank you

zack
  • 5,205
  • 1
  • 19
  • 25
  • Maybe you pattern should be something like `[0-9]{2}\[0-9]{2}\[0-9]{2}`. This works? – tk3 May 17 '18 at 13:42
  • `[0-9]` matches only one number. You need to use a quantifier (`+` or `{2}`) after each. Also, you need to escape the backslashes with another backslash `\\` – divibisan May 17 '18 at 13:42
  • You might be able to get away with `"[\\d\\]+"` for just a string of digits and backslashes, if there are not likely to be any in a different configuration. – Andrew Gustar May 17 '18 at 13:55

2 Answers2

0

I think you may need lazy matching for regex, unless there's always two digits - in which case other responses look valid.

If you could provide a vector of file name strings, that would be super helpful.

Capturing backslashes is confusing, I've found this thread helpful: R - gsub replacing backslashes

My guess is something like this: '[0-9]+?\\\\[0-9]+?\\\\[0-9]+'

zack
  • 5,205
  • 1
  • 19
  • 25
0

This Regex works for 10\11\18.

(\d\d\\\d\d\\\d\d)
Laurent Mouchart
  • 216
  • 1
  • 3
  • 13