Is there a ready-made function for this? If not, how can you write it. Thank!
- And where does your file come from? - Alexey Ten
- the file is on the server, before writing to it, you need to know if it is empty or not, it depends on what to do with it. - Alexey Antonovich
- fs.stat or statSync nodejs.org/dist/latest-v4.x/docs/api/… - Alexey Ten
|
1 answer
var buf = new Buffer(1024); fs.open('input.txt', 'r+', function(err, fd) { if (err) { return console.error(err); } fs.read(fd, buf, 0, 1024, 0, function(err, bytes){ if (bytes == 0){ console.log("File is empty"); } }) })
- I understand files.length is a check if the directory is empty. Is the file empty? - Alexey Antonovich
- @AlexeyAntonovich should warn where the file to check ... - C.Raf.T
- @AlexeyAntonovich changed .. It can be so ... - C.Raf.T
- @ C.Raf.T for file information is fs.stat - Alexey Ten
|