Get files matching regex pattern in node.js (coffeescript).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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