Skip to content

Instantly share code, notes, and snippets.

@johanatan
Created August 26, 2013 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanatan/6338182 to your computer and use it in GitHub Desktop.
Save johanatan/6338182 to your computer and use it in GitHub Desktop.
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 _.map (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