Horje
Get List of all files in a directory in Node.js Code Example
node get all files in folder
fs.readdir('./', (err, files) => {
    files.forEach(file => {
    //   console.log(file);
})});
Get List of all files in a directory in Node.js
const testFolder = './tests/';
const fs = require('fs');

fs.readdir(testFolder, (err, files) => {
  files.forEach(file => {
    console.log(file);
  });
});
node list files in directory

//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); 
    });
});
javascript get list of files in directory
var fs = require('fs');
var files = fs.readdirSync('/downloads');




Javascript

Related
hr react Code Example hr react Code Example
read directory in node js Code Example read directory in node js Code Example
font awesome 4.7 cdn Code Example font awesome 4.7 cdn Code Example
font awesome 4.7cdn Code Example font awesome 4.7cdn Code Example
fibonacci sequence in javascript using for loop Code Example fibonacci sequence in javascript using for loop Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7