Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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); 
    });
});
Comment

node list folders in directory

const { readdir } = require('fs')

const getDirectories = (source, callback) =>
  readdir(source, { withFileTypes: true }, (err, files) => {
    if (err) {
      callback(err)
    } else {
      callback(
        files
          .filter(dirent => dirent.isDirectory())
          .map(dirent => dirent.name)
      )
    }
  })
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery einbinden in js 
Javascript :: run js function after some sec 
Javascript :: scroll to bottom 
Javascript :: make url clickable js 
Javascript :: check whether a checkbox is checked in jQuery 
Javascript :: ace get contents of editor 
Javascript :: how to create external link javascript 
Javascript :: react useref file input 
Javascript :: jQuery get values of selected checkboxes 
Javascript :: select option trigger in js 
Javascript :: make string json object vue 
Javascript :: jquery select option value id no not exists 
Javascript :: wordpress add jquery script 
Javascript :: how to remove element from array react native 
Javascript :: digitalocean app platform node version 
Javascript :: MongoParseError: option usecreateindex is not supported 
Javascript :: remove duplicates from array js lodash 
Javascript :: update all dependencies npm 
Javascript :: Another debugger is already connected Rn @ bundle.js:10 
Javascript :: how to check if an element is in an array javascript 
Javascript :: javascript oncontextmenu 
Javascript :: discord.js bot activity 
Javascript :: js ask before close 
Javascript :: vue check if list is empty 
Javascript :: cypress scroll bottom 
Javascript :: add favicon to next js static site 
Javascript :: random choice js array 
Javascript :: string to kebab case 
Javascript :: set year in javascript 
Javascript :: javascript int with commas 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =