基本上我想让async.eachSeries以5秒的间隔运行,然后再执行另一个....
我有2个函数...第1个函数读取文本文件并将每个行值存储在一个数组中。我的阵列将有大约20 000个项目。它还调用第二个函数,并运行async.eachSeries。第二个函数接受数组(20 000)并将每个数组分成更小的数组......(5000)。
以下是我的第一个功能:
var LineReader = reader.createInterface({
input: fileReader.createReadStream('lines.txt')
});
LineReader.on('line', function (line) {
var NewNumber = line.toString();
number_list.push(NewNumber);
});
LineReader.on('close', function(){
var chunkData = chunk(5000, number_list);
async.eachSeries(chunkData, function(chunk, callback) {
console.log(chunk.length);
callback(null);
})
});
第二功能
function chunk(chunk_size, array) {
return array.reduce(function(previous, current) {
var chunk;
if (previous.length === 0 ||
previous[previous.length - 1].length === chunk_size) {
chunk = [];
previous.push(chunk);
} else {
chunk = previous[previous.length - 1];
}
chunk.push(current);
return previous;
}, []);
}
答案 0 :(得分:1)
这可以解决这个问题吗?
ubuntu:~/stackoverflow$ find ./ -type f -name \*.mpeg -exec rename -v
's/^(.*)\/.*.mpeg$/$1\/video.mpeg/' {} \;
./dir1/dir2/dir3/test.mpeg renamed as ./dir1/dir2/dir3/video.mpeg
./dir1/dir2/dir3/dir4/test.mpeg renamed as
./dir1/dir2/dir3/dir4/video.mpeg
./dir1/dir2/test.mpeg renamed as ./dir1/dir2/video.mpeg
./dir1/test.mpeg renamed as ./dir1/video.mpeg