Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Strange behaviors of fs.readdir(dir) and process.chdir(dir) on Windows when 'dir' is a dive letter #4688

@duanyao

Description

@duanyao

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions