fshost / node-dir

Recursive asynchronous file and directory operations for Node.js
MIT License
221 stars 44 forks source link

`\\` output #24

Closed rodoabad closed 9 years ago

rodoabad commented 9 years ago

Windows machine. This module outputs double slashes for paths.

fshost commented 9 years ago

That's due to how javascript deals with strings containing a backslash, which by default is an escape character, so "\foo\bar" is how you would represent the string \foo\bar as a string literal in javascript. A string literal of "\foo\bar" would be interpreted as escaping the characters after the backslashes. To see what I mean, go into a javascript console and type console.log("\foo\bar"). The output if you do this in the node.js REPL is a blank line followed by oar. If you type console.log("\foo\bar") the output will be \foo\bar. The double backslash is the only way to handle the Windows style path separator symbol properly as contained in a string, and its not really node-dir that's doing this, its the node.js javascript engine. You can read about this issue on stack exchange here.