This article mainly introduces node. fs. this document describes the usage of the readdir method. readdir method description, syntax, receive parameters, use instances, and implement Source Code. For more information, see
Method description:
Read the file directory asynchronously.
Syntax:
The Code is as follows:
Fs. readdir (path, [callback (err, files)])
Because this method belongs to the fs module, we need to introduce the fs module (var fs = require ("fs") before use "))
Receiving parameters:
Path directory path
Callback: two parameters are passed: err and files. files is an array containing "names of all files in the specified directory.
Example:
The Code is as follows:
Var fs = require ('fs ');
Fs. readdir ('readdirtest', function (err, files ){
If (err ){
Console. log (err );
}
Console. log (files );
})
Source code:
The Code is as follows:
Fs. readdir = function (path, callback ){
Callback = makeCallback (callback );
If (! NullCheck (path, callback) return;
Binding. readdir (pathModule. _ makeLong (path), callback );
};