Get List of all files in a directory in Node.js

https://medium.com/stackfame/get-list-of-all-files-in-a-directory-in-node-js-befd31677ec5

//requiring path and fs modules
const path = require('path');
const fs = require('fs');
//joining path of directory
const directoryPath = path.join(__dirname, 'Documents');
//passsing directoryPath and callback function
fs.readdir(directoryPath, function (err, files) {
//handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
}
//listing all files using forEach
files.forEach(function (file) {
// Do whatever you want to do with the file
console.log(file);
});
});

Không có nhận xét nào:

SO SÁNH 5 “ĐỨA CON AI” HOT NHẤT 2025

 https://www.facebook.com/AInews2023/posts/pfbid031usNyqqvstcDbFaRptkJmG3ReiTUUmGxGE5fp5PqPKqaseVRqVsoypKNS5CBRzNJl?__cft__[0]=AZUVx56Rvbt3n...