Skip to content

Instantly share code, notes, and snippets.

@kurtsson
Created October 24, 2014 22:21
Show Gist options
  • Save kurtsson/6d528c1698e1a5f8f161 to your computer and use it in GitHub Desktop.
Save kurtsson/6d528c1698e1a5f8f161 to your computer and use it in GitHub Desktop.
FileList, list all files recursive in a directory that matches the expression
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