Created
          March 2, 2011 19:20 
        
      - 
      
- 
        Save willbailey/851513 to your computer and use it in GitHub Desktop. 
    node list files matching a regex recursively
  
        
  
    
      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
    
  
  
    
  | var fs = require('fs'); | |
| var listFiles = function(path, match) { | |
| var files = []; | |
| var paths = fs.readdirSync(path); | |
| paths.forEach(function(file) { | |
| var stats = fs.statSync(path + '/' + file); | |
| if (stats.isDirectory()) { | |
| files = files.concat(listFiles(path + '/' + file, match)); | |
| } else { | |
| if (file.match(match)) { | |
| files.push(file); | |
| } | |
| } | |
| }); | |
| return files; | |
| }; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment