1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| var fs = require('fs'); var path = require('path');
var filePath = path.resolve('E:'); const tinify = require('tinify') tinify.key = "WpYVeU3DkB5v6oQJRPAijtBhFdP5wn5D";
fileDisplay(filePath);
function fileDisplay(filePath){ fs.readdir(filePath,function(err,files){ if(err){ console.warn(err) }else{ files.forEach(function(filename){ var filedir = path.join(filePath,filename); fs.stat(filedir,function(eror,stats){ if(eror){ console.warn('获取文件stats失败'); }else{ var isFile = stats.isFile(); var isDir = stats.isDirectory(); if(isFile){ console.log(filedir); setTimeout(()=>{tinify.fromFile(filedir).toFile(filedir)}); } if(isDir){ fileDisplay(filedir); } } }) }); } }); }
|