T
T
Tipylja2018-08-14 10:26:22
Node.js
Tipylja, 2018-08-14 10:26:22

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);
        });

     });

Tell me how to loop through the nested directories, while maintaining this hierarchy

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question