fs.readdir(path[,
options], callback)
This
method read the contents of a directory asynchronously. Below table summarizes
the arguments of readdir method.
Argument
|
Type
|
Description
|
|||||||||
path
|
string
or Buffer or URL
|
Absolute
path of the file
|
|||||||||
options
|
string
or Object
|
Below
table summarizes different options.
|
|||||||||
callback
|
Function
|
This
function executes when the readdir executes successfully.
Below
table summarizes the arguments of callback function.
|
Find
the below working example.
var fs = require('fs'); var path = 'C:\\Users\\Public\\demo'; fs.readdir(path, (error, fileNames) => { if (error) { console.log('Error occured while read the files'); return; } console.log(fileNames); }); console.log('Done.......')
No comments:
Post a Comment