1

I have been going through stackoverflow topics to find anything useful and there is really nothing. What i would need is (probably) some module, which you can call like this:

someModule('/start/path/', 'list', function(err, list) { // list contains properly structured object of all subdirectories and files }); 

also this

someModule('/start/path/', 'remove', function(err, doneFlag) { // doneFlag contains something like true so i can run callback }); 

I need above functionalities to create mini web-build ftp/code editor for my students.

It is important that listing includes correct structure of NOT only files but also subdirectories they are in. It doesnt really have to be that easy like in my desirable example, most important is that functionality is there. Thank you for all recomendations.

1 Answer 1

2

I made a module for my own needs which may help you. Look at alinex-fs. This is an extension of the node.js fs module and can be used as replacement.

Additionally it has a very powerful fs.find() method which will search recursively and match files like the linux find command. What to search for is done by an easy configuration hash. Then you may loop over the result and remove everything (also recursive).

An example use may look like:

# include the module var fs = require('alinex-fs'); # search asynchronouse fs.find('/tmp/some/directory', { include: 'test*', type: 'dir' modifiedBefore: 'yesterday 12:00' # and much more possibilities... }, function(err, list) { if (err) return console.error(err); # async included here for readability but mostly moved to top var async = require('async'); # parallel loop over list async.each(list, function(file, cb) { # remove file or dir return fs.remove(file, cb); }, function(err) { if (err) return console.log(err); console.log('done'); }); }); 

if you already have the list of entries which you need to remove, you can also only use the inner function of the above code.

I hope that will help you to come a step further. If not please make your question more specific.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.