Created
October 24, 2014 22:21
-
-
Save kurtsson/6d528c1698e1a5f8f161 to your computer and use it in GitHub Desktop.
FileList, list all files recursive in a directory that matches the expression
This file contains hidden or 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
fs = require('fs') | |
class FileList | |
constructor: (dir,exp = '') -> | |
@fileList = [] | |
@pattern = new RegExp(exp) | |
@getFiles(dir) | |
getFiles: (dir) -> | |
files = fs.readdirSync(dir) | |
for file in files | |
name = "#{dir}/#{file}" | |
if fs.statSync(name).isDirectory() | |
@getFiles(name) | |
else | |
if @pattern.test(name) | |
@fileList.push(name) | |
files = new FileList('source','.coffee') #All .coffee files in the source dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment