Created
April 9, 2014 07:43
-
-
Save shepherdwind/10237220 to your computer and use it in GitHub Desktop.
getScreenFile
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
#!/usr/bin/env node --harmony | |
var fs = require('fs') | |
var path = require('path') | |
var co = require('co') | |
var thunkify = require('thunkify') | |
var cwd = process.cwd() | |
var file = path.join(cwd, 'templates') | |
var dir = thunkify(fs.readdir) | |
var stat = thunkify(fs.stat) | |
function getScreenFile(file){ | |
co(function*(){ | |
var dirs = yield dir(file) | |
for (var i = 0; i < dirs.length; i++) { | |
var filename = path.join(file, dirs[i]) | |
var filestat = yield stat(filename) | |
if (filestat.isDirectory()) { | |
// 如果是文件夹,并且不是隐藏文件,并且不是tile目录的情况下,递归查找 | |
if(filename.indexOf('.') !== 0 && filename.indexOf('tile') === -1) { | |
getScreenFile(filename) | |
} | |
// 找到所有文件名中又screen的文件 | |
} else if (filename.indexOf('screen') > -1) { | |
console.log(filename) | |
} | |
} | |
})() | |
} | |
getScreenFile(file) | |
/** | |
* vim: ft=javascript:tw=80: | |
* requires: co, thunkify | |
*/ |
嗯,find是要容易一些,头晕了,不记得当时怎么想的。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以用这个 fs https://github.com/visionmedia/co-fs
放到数组不是 push 么,不是很明白
话说这个功能用 find 更简单吧