`var fs = require('fs')
fs.writeFileSync( "AUX.txt", "test", function(err){return console.log(err)} )
console.log( fs.readFileSync( "AUX.txt", {encoding: 'utf-8'}) )`
Always given the provided path "AUX.txt", independently of extension given (tested: "txt" / "js" / null), using another name does not fail.
A file normally accessible via the OS
"\\.\AUX" cannot be opened"\\." doesn't existCannot find the \\.\AUX.txt fileCould you provide full paths of files you are trying to access?
Are you opening the file via default file manager under the same user that run the file-creation script?
Could you be writing file in a different location than you expect (this fs.writeFileSync( "AUX.txt", will write the file in the directory where the script is invoked)?
Also, fs.writeFileSync( "AUX.txt", "test", function(err){return console.log(err)} ) this function doesn't have a callback (the 3rd argument is an options object).
To be clear writeFile creates OS inaccessible file - is an impossible situation because the OS is who actually creates the file and makes any modifications to it, the Node.js (via libuv to be specific) just makes calls (syscall) to the OS to perform those actions.
Much appreciated for your help. You are correct, this has nothing to do with node itself, my apologies.
As it turns out "AUX" is one of many reserved filenames* on this OS.
CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9
Given your last hint I attempted to create a file with the same name "AUX.txt" via the OS itself and it fails with the reserved filename explanation. Somehow node must access a deeper api bypassing the restriction, both for writing and reading.
I was caught off guard here. I was generating filenames dynamically for some output and only the AUX.txt file was giving me trouble. I figured the issue had to be deeper than my code, I just did not expect it to be as deep as the OS. Thanks again.
This should probably be closed.
I was not aware of such a requirement on Windows, glad you solved your issue.
Perhaps we can handle this better on Windows so ping @nodejs/platform-windows @nodejs/libuv to give your opinion if this is actionable somehow.
Node uses file namespace paths for file access. We do that so we do not get hit by the 260 path limit, but as a side effect, you can create files with reserved names.
Those files are accessible, the app you are using just must support it. You can try opening the file with \\.\[absolute path to the file].
Anyway, there is nothing for Node to fix here.
Most helpful comment
Node uses file namespace paths for file access. We do that so we do not get hit by the 260 path limit, but as a side effect, you can create files with reserved names.
Those files are accessible, the app you are using just must support it. You can try opening the file with
\\.\[absolute path to the file].Anyway, there is nothing for Node to fix here.