Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get the files deleted? #13

Closed
denisz1 opened this issue Dec 4, 2014 · 2 comments
Closed

How can I get the files deleted? #13

denisz1 opened this issue Dec 4, 2014 · 2 comments

Comments

@denisz1
Copy link

denisz1 commented Dec 4, 2014

Is it possible through some option to return a set of filenames/paths which were actually deleted (i.e. which matched my pattern)?

@denisz1
Copy link
Author

denisz1 commented Dec 9, 2014

@sindresorhus The array returns deleted files, and deleted directories (if you used a globbing pattern). This makes sense, because the array contains deleted paths, and if any directories were deleted, then they should be included in that array.

And yet... should that be the case? My expectation was the array contains files deleted, not directories.

I expect this is a tricky one, because some people may want them included in the array, and others would not. I don't want them included, but I'm sure others will have a use case for it.

What do you think?

@denisz1
Copy link
Author

denisz1 commented Dec 11, 2014

@sindresorhus This is what I mean. If I knew how to use GIT I would submit the following change... Sorry!

By default, the returned array contains all paths deleted, both directories and files. But if you set the option.returnFilesOnly to true, then the array will only contain files.

This is what I think many, but not all people, would really be interested in. And they can have it both ways depends on their use case.

var fs = require('fs');

module.exports = function (patterns, opts, cb) {
// ...
  if (opts.returnFilesOnly) {
    fs.stat(el, function(err, stats) {
      if (stats.isFile()) {
        deletedFiles.push(el);
      }
    })
  }
  else {
    deletedFiles.push(el);
  }
  rimraf(el, next);
// ...
};

// ...

module.exports.sync = function (patterns, opts) {
// ...
  if (opts.returnFilesOnly) {
    if (fs.statSync(el).isFile()) {
      deletedFiles.push(el);
      }
  }
  else {
    deletedFiles.push(el);
  }
  rimraf.sync(el);
// ...
};

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant