CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2020-09-25
by PatricNox

Original Post

Original - Posted on 2010-04-28
by Christian C. Salvadó



            
Present in both answers; Present only in the new answer; Present only in the old answer;

You can use the [`fs.readdir`][1] or [`fs.readdirSync`][2] methods.
**fs.readdir**
const testFolder = './tests/'; const fs = require('fs');
fs.readdir(testFolder, (err, files) => { files.forEach(file => { console.log(file); }); });
**fs.readdirSync**
const testFolder = './tests/'; const fs = require('fs');
fs.readdirSync(testFolder).forEach(file => { console.log(file); });
The difference between the two methods, is that the first one is asynchronous, so you have to provide a callback function that will be executed when the read process ends.
The second is synchronous, it will return the file name array, but it will stop any further execution of your code until the read process ends.
[1]: https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback [2]: https://nodejs.org/api/fs.html#fs_fs_readdirsync_path_options
You can use the [`fs.readdir`][1] or [`fs.readdirSync`][2] methods.
**fs.readdir**
const testFolder = './tests/'; const fs = require('fs');
fs.readdir(testFolder, (err, files) => { files.forEach(file => { console.log(file); }); });
**fs.readdirSync**
const testFolder = './tests/'; const fs = require('fs');
fs.readdirSync(testFolder).forEach(file => { console.log(file); });
The difference between the two methods, is that the first one is asynchronous, so you have to provide a callback function that will be executed when the read process ends.
The second is synchronous, it will return the file name array, but it will stop any further execution of your code until the read process ends.
[1]: https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback [2]: https://nodejs.org/api/fs.html#fs_fs_readdirsync_path_options

        
Present in both answers; Present only in the new answer; Present only in the old answer;