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

Add isEmpty and isEmptySync methods so that I don't need to use 'extfs' as well as 'fs-extra' #420

Closed
kruncher opened this issue May 6, 2017 · 7 comments

Comments

@kruncher
Copy link

kruncher commented May 6, 2017

It would be nice to avoid the need to be dependent on 2 separate packages fs-extra and extfs when doing file manipulations:

const fs = require("fs-extra");
const extfs = require("extfs");

It would be nice if fs-extra included isEmpty and isEmptySync methods such that the following is possible:

if (fs.isEmptySync(path)) {
    console.log("The specified directory is empty!");
}

or:

fs.isEmpty(path).then(isEmpty => {
  if (isEmpty) {
    console.log("The specified directory is empty!");
  }
});
@jprichardson
Copy link
Owner

@kruncher can you elaborate on the use case?

@kruncher
Copy link
Author

kruncher commented May 7, 2017

@jprichardson To determine whether or not a directory is empty.

To be more specific, in my current use case, I want to run some logic if the given directory is empty but I want to stay clear and present the end-user with an error message if it contains files and/or sub-directories.

The implementation provided by extfs does the job nicely and these two methods seem like a natural fit for fs-extra since both of these libraries augment the built-in fs with their extra functions.

@jprichardson
Copy link
Owner

To be more specific, in my current use case, I want to run some logic if the given directory is empty but I want to stay clear and present the end-user with an error message if it contains files and/or sub-directories.

Can you elaborate more here? What logic do you want to run if it's empty? Why would you not just present an error message if the directory exists?

I'm trying to figure out the strong use case of not just checking if the directory exists? i.e. why is that not good enough?

@kruncher
Copy link
Author

kruncher commented May 8, 2017

Why would you not just present an error message if the directory exists?

Because the empty directory is created by an entirely different process.

@Inve1951
Copy link

Inve1951 commented May 27, 2017

you could use the native fs.readdir(path, cb) with cb as:

function (err, files) {
  var isEmpty = !files.length
  ...
}

no need for a whole library to avoid 1 line of code.

hope this helps you.

@RyanZim
Copy link
Collaborator

RyanZim commented Jun 21, 2017

@jprichardson What's the decision here?

@RyanZim
Copy link
Collaborator

RyanZim commented Jul 29, 2017

Overall, this feels like a tiny edge-case not worth supporting. Closing at least for now.

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

4 participants