Answer the question
In order to leave comments, you need to log in
How to loop through the file system?
There is a directory and directories nested in it that contain photos, I need to go through all the files in these directories, process the photos and put them in another directory, but at the same time preserve the structure. If there is only one directory and files in it, then this is easy to do:
var fs = require('fs')
, gm = require('gm');
var data = fs.readdirSync('img');
data.map(function(item, i, arr) {
gm('img/' + item)
.write('opt/' + item, function (err) {
if (err) console.log(err);
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question