Skip to content

Instantly share code, notes, and snippets.

Created August 26, 2013 04:48
What would you like to do?
Get files matching regex pattern in node.js (coffeescript).
getFilesMatching = (pattern) ->
splitted = pattern.split '/'
[dir, pattern] = [((_.initial splitted).join '/'), _.last splitted]
pattern = (pattern.replace '.', '\.').replace '*', '.*' # convert shell regex to PCRE
_.compact (fs.readdirSync dir), (f) -> if f.match pattern then "#{dir}/#{f}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment