I am using Node.js
.
I want to check if folder is empty or not? One option is to use fs.readdir but it loads whole bunch of
This is an ugly hack but I'll throw it out there anyway. You could just call fs.rmdir
on the directory. If the callback returns an error which contains code: 'ENOTEMPTY'
, it was not empty. If it succeeds then you can call fs.mkdir
and replace it. This solution probably only makes sense if your script was the one which created the directory in the first place, has the proper permissions, etc.