My test code for fs.readdir:
d:\project\MyNodeJS\dir.js:
var fs = require('fs');
var dir = process.argv[2];
fs.readdir(dir, function(error, files) {
if (error) {
console.log(error);
return;
}
for (var i = 0; i < files.length; ++i) {
console.log(files[i]);
}
});
Run the code (suppose the current directory is C:\Users\Administrator):
C:\Users\Administrator>cd /d d:\
d:\>node d:\project\MyNodeJS\dir.js c:
The output is the file list of current directory on drive c:(C:\Users\Administrator).
I think fs.readdir() should throw an error here because "c:" is not a directory.
My test code for process.chdir:
d:\project\MyNodeJS\cd.js:
var dir = process.argv[2];
process.chdir(dir);
console.log("current dir: " + process.cwd());
Run the code:
C:\Users\Administrator>cd /d d:\
d:\>node d:\project\MyNodeJS\cd.js c:
Output:
current dir: C:\Users\Administrator
I think process.chdir() should also throw an error here because "c:" is not a directory.
I also notice that Windows command 'dir' and 'cd' have samilar behaviors as dir.js and cd.js, treating a dive letter as the current directory on that drive. These behaviors are not documented, so I don't know whether they are features or bugs.
I tested node 0.8.18 on Windows 7 32bits system.