Windows 8.3 File Names

275 views
Skip to first unread message

Joran Dirk Greef

unread,
Aug 20, 2014, 1:39:30 AM8/20/14
to nod...@googlegroups.com
I am working on file synchronization and would like to know how Node.js receives file names from Windows when calling fs.stat or fs.readdir?

Does Node.js always return the 8.3 file name equivalent of a long file name on Windows? Or does this depend on the version of Windows in use? Will Node.js sometimes return the long file name?

For instance, one could use Node.js to write out a file on Windows with a long file name. Then trying to check for its existence later by calling fs.readdir on the parent directory might perhaps return an 8.3 file name in the results without the long file name. Would this be possible?

Is there anyway to get both the 8.3 file name and long file name using Node.js?

See here for more detail: http://support.microsoft.com/kb/142982

Ben Noordhuis

unread,
Aug 20, 2014, 5:21:18 PM8/20/14
to nod...@googlegroups.com
On Wed, Aug 20, 2014 at 7:39 AM, Joran Dirk Greef <jo...@ronomon.com> wrote:
> I am working on file synchronization and would like to know how Node.js
> receives file names from Windows when calling fs.stat or fs.readdir?

Node.js (or rather, libuv) uses the wide character versions of the NT
API for most things. For example, fs.stat() calls CreateFileW() and
fs.readdir() calls FindFirstFileW() and FindNextFileW().

(Note: The NT API uses UTF-16, libuv UTF-8. Libuv internally converts
to and from UTF-16.)

> Does Node.js always return the 8.3 file name equivalent of a long file name
> on Windows? Or does this depend on the version of Windows in use? Will
> Node.js sometimes return the long file name?
>
> For instance, one could use Node.js to write out a file on Windows with a
> long file name. Then trying to check for its existence later by calling
> fs.readdir on the parent directory might perhaps return an 8.3 file name in
> the results without the long file name. Would this be possible?

I don't think libuv ever returns the 8.3 file name. However, I
believe that when (and someone with more Windows experience correct me
if I'm wrong):

1. You create a file or directory with a "long" path (i.e. has a \\?\
prefix and is up to approx. 32,768 characters long), and then

2. Try to reference it through a "short" path (up to MAX_PATH or 260
characters - slightly less for directories), then

3a. You either get a path that's truncated to MAX_PATH characters
(e.g. when scanning a directory), or

3b. You cannot access the file system entity (e.g. when trying to open it.)

3a applies to fs.readdir(). FindFirstFileW() and FindNextFileW()
operate on a WIN32_FIND_DATA structure that's limited to MAX_PATH
characters.

3b is applicable to fs.stat() when you use a "short" path.

> Is there anyway to get both the 8.3 file name and long file name using
> Node.js?

No. You could write a small add-on for GetShortPathName(), however.

> See here for more detail: http://support.microsoft.com/kb/142982

Caveat emptor, that article says the path limit is 255 characters but
that's not quite right.

Angel Java Lopez

unread,
Aug 20, 2014, 5:21:23 PM8/20/14
to nod...@googlegroups.com
AFAIK, Node.js returns and use the long name.

Indeed, I don't know how to retrieve the short name using node ;-)

Other comments?

Angel "Java" Lopez
@ajlopez



--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/b8afa9b6-4d03-48ab-8c0d-4ded8ad4d37f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joran Dirk Greef

unread,
Aug 21, 2014, 2:34:34 AM8/21/14
to nod...@googlegroups.com
Thanks Ben

I found an interesting scenario on Windows because of the 8.3 file names (it's not the fault of Node or libuv):

1. You already have a file on disk called ABCDEFGHIJ.txt with content in it
2. You intend to create another different file called "ABCDEF~1.TXT" and call fs.writeFile('ABCDEF~1.TXT', '')
3. Instead of ending up with two files, ABCDEFGHIJ.txt now has no content in it, and there is still no file called "ABCDEF~1.TXT"

This is because the 8.3 file name of ABCDEFGHIJ.txt is actually "ABCDEF~1.TXT".

xx

unread,
Aug 30, 2014, 11:39:53 PM8/30/14
to nod...@googlegroups.com
try fswin.
i had the same problem years ago.
Reply all
Reply to author
Forward
0 new messages