“Węzeł Pobierz wszystkie pliki w folderze” Kod odpowiedzi

Węzeł Pobierz wszystkie pliki w folderze

fs.readdir('./', (err, files) => {
    files.forEach(file => {
    //   console.log(file);
})});
Adventurous Aardvark

Uzyskaj listę wszystkich plików w katalogu w Node.js

const testFolder = './tests/';
const fs = require('fs');

fs.readdir(testFolder, (err, files) => {
  files.forEach(file => {
    console.log(file);
  });
});
Fragile Ferret

Pliki listy węzłów w katalogu


//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); 
    });
});
Clever Crane

węzeł JS otrzymuje pliki w Dir

const path = require('path');
const fs = require('fs');

fs.readdir(
  path.resolve(__dirname, 'MyFolder'),
  (err, files) => {
    if (err) throw err;
    
    for (let file of files) {
      console.log(file);
    }
  }
);
garzj

Jak odczytać wszystkie pliki w folderze w węźle JS

fs.readdir('./', (err, files) => {
        files.forEach(file => {
        //   console.log(file);
        }});
Alien0w0

Odpowiedzi podobne do “Węzeł Pobierz wszystkie pliki w folderze”

Pytania podobne do “Węzeł Pobierz wszystkie pliki w folderze”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu