Node: reserved name file creating in windows?

Created on 23 Apr 2018  路  5Comments  路  Source: nodejs/node

  • Version: 7.9.0
  • Platform: windows 10 64 bit
  • Subsystem: fs


fs module in nodejs allow file creation with a reserved name in windows system

I am not familiar with the nodejs repo, is someone can go check for it?
But creating reservd name file in windows is not a good idea.

https://github.com/atom/atom/issues/17175

fs windows

Most helpful comment

I'd say it is intended and shouldn't be documented. It's a Windows quirk, unrelated to Node.js.

All 5 comments

Test:

'use strict';

const fs = require('fs');

const winReservedNames = [
  'CON', 'PRN', 'AUX', 'NUL',

  'COM0', 'COM1', 'COM2', 'COM3', 'COM4',
  'COM5', 'COM6', 'COM7', 'COM8', 'COM9',

  'LPT0', 'LPT1', 'LPT2', 'LPT3', 'LPT4',
  'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9',
];

const testDir = 'test-win-reserved-names';

fs.mkdirSync(testDir);

winReservedNames.forEach((name) => {
  console.log(`${name}: ${fs.openSync(`${testDir}/${name}`, 'w')}`);
});

console.log(fs.readdirSync(testDir));


Output:

> node test.j
CON: 3
PRN: 4
AUX: 5
NUL: 6
COM0: 7
COM1: 8
COM2: 9
COM3: 10
COM4: 11
COM5: 12
COM6: 13
COM7: 14
COM8: 15
COM9: 16
LPT0: 17
LPT1: 18
LPT2: 19
LPT3: 20
LPT4: 21
LPT5: 22
LPT6: 23
LPT7: 24
LPT8: 25
LPT9: 26
[ 'AUX',
  'COM0',
  'COM1',
  'COM2',
  'COM3',
  'COM4',
  'COM5',
  'COM6',
  'COM7',
  'COM8',
  'COM9',
  'CON',
  'LPT0',
  'LPT1',
  'LPT2',
  'LPT3',
  'LPT4',
  'LPT5',
  'LPT6',
  'LPT7',
  'LPT8',
  'LPT9',
  'NUL',
  'PRN' ]


The files or the folder can be deleted only with UNC \\?\ prefix.

cc @nodejs/platform-windows @nodejs/documentation
It seems we do not document this case in fs doc for fs.open() and counterparts. Is this behavior intended? Should we document it?

Refs: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions

I'd say it is intended and shouldn't be documented. It's a Windows quirk, unrelated to Node.js.

I'll close this out as working as expected.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dfahlander picture dfahlander  路  3Comments

Icemic picture Icemic  路  3Comments

srl295 picture srl295  路  3Comments

mcollina picture mcollina  路  3Comments

akdor1154 picture akdor1154  路  3Comments