神磨 stdin = process.stdin,
stdout = process.stdoutvar stats = []fs.readdir(process.cwd(), function(err, files) {
console.log(' ')
if (!files.length) {
return console.log(' \033[31m No files to show!\033[39m\n')
}
function file(i) {
var filename = files[i]
fs.stat(__dirname + '/' + filename, function(err, stat) {
stats[i] = stat
if (stat.isDirectory()) {
console.log(' ' + i + ' \033[36m' + filename + '/\033[39m')
} else {
console.log(' ' + i + ' \033[90m' + filename + '\033[39m')
}
i++
if (i == files.length) {
read()
孙者 } else {
file(i)
}
})
}
function read() {
console.log(' ')
stdout.write(' \033[33mEnter your choice : \033[39m')
stdin.resume()
stdin.setEncoding('utf8')
stdin.on('data', option)
}
function option(data) {
var filename = files[Number(data)]
if (!files[Number(data)]) {
stdout.write(' \033[mEnter your choice : \033[39m')
} else if (stats[Number(data)].isDirectory()) {
fs.readdir(__dirname + '/' + filename, function(err, files) {
console.log(' ')
console.log(' (' + files.length + 'files)')
files.forEach(function(file) {
console.log(' - ' + file)
})
console.log(' ')
})
} else {
stdin.pause()
fs.readFile(__dirname + '/' + filename, 'utf8', function(err, data) {
则瞎薯console.log(' ')
console.log('\033[90m' + data.replace(/(.*) /g, ' $1') + '\033[39m')
})
}
}
file(0)})
function findSync(startPath) {
隐冲 let result=[]
明咐 function finder(path) {
let files=fs.readdirSync(path)
files.forEach((val,index) =>{
let fPath=join(path,val)
let stats=fs.statSync(fPath)
if(stats.isDirectory()) finder(fPath)
if(stats.isFile()) result.push(fPath)
})
}
finder(startPath)
激携纯 return result
}
let fileNames=findSync('./')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)