筆記,原文網址: http://stackoverflow.com/questions/6959462/in-node-js-reading-a-directory-of-html-files-and-searching-for-element-attribu
1 2 3 4 5 6 7 8 9 10 11 12 | var fs = require('fs'); fs.readdir('/path/to/html/files', function(err, files) { files.filter(function(file) { return file.substr(-5) === '.html'; }) .forEach(function(file) { fs.readFile(file, 'utf-8', function(err, contents) { inspectFile(contents); }); }); }); function inspectFile(contents) { if (contents.indexOf('data-template="home"') != -1) { // do something } } |