const tinify = require('tinify');
tinify.key = 'AAAAAAAAAA';
var path = require('path');
var fs = require('fs');
var pathName = './source';
fs.readdir(pathName, function (err, files) {
var dirs = [];
(function iterator (i) {
if (i == files.length) {
console.log(dirs);
return;
}
fs.stat(path.join(pathName, files[i]), function (err, data) {
if (data.isFile()) {
try {
dirs.push(files[i]);
console.log('S---------------------' + files[i] + '---------------------S')
const source = tinify.fromFile('./source/' + files[i]);
source.toFile('./target/' + files[i]);
console.log('E---------------------' + files[i] + '---------------------E')
} catch (e) {
console.log('EEE---------------------' + files[i] + '---------------------EEE')
}
}
iterator(i + 1);
});
})(0);
console.log(dirs);
});
网友评论