FYI- Inadvertent Error to keep in mind CON/AUX/NUL/COMx/LPTx reserved names

Just wanted to save some hair pulling.

Back int the late 90's I ran into some weird errors in my code projects when working with futures text files. Had specifically to do with a root symbol "CON". Anytime I tried to read or write a CON.TXT file, my coded program would crash. After a great amount of wasted time debugging file write operations, I was to learn that CON.txt is some type of windows protected file, even when used in a folder.

Yesterday it can back! So just as an FYI to everyone, Nasdaq started trading a symbol "CON", so if you run into some weird problems, likely you are trying to write to a CON.txt file.

"CON" is not "protected file". It is reserved file system name for console.
It is Microsoft leftover from old MS-DOS days.

If you try to add symbol "CON" in Amibroker it would handle it perfectly.
AmiBroker knows that "CON" is one of those Microsoft/DOS file system reserved names,

and AmiBroker would create "CO_" filename instead it its quotation database.

https://answers.microsoft.com/en-us/windows/forum/all/file-name-as-con-cannot-be-created-on-desktop-can/c41e136a-56ac-4385-b119-3773cdee7a9c

Problem starts when you are writing files YOURSELF.

When you call fopen() funciton, what is called is C runtime function fopen() without any "babysitting" layer the same as fopen() C runtime would be called if you write a program in C/C++ or any other compiled language.

In Windows file system you can't use file names with:
CON, AUX, NUL, COM1-COM9, PRN, LPT1-LPT9

as these have special meaning for virtual DOS devices (console, serial port, printer, etc)

If you try that from C/C++ the same thing will happen - it will fail.

You are also not able to create such files from any other application and Windows file explorer.

And yes, CON with any extension is forbidden, so you can't use CON.txt, CON.xls, CON.doc, etc in Windows, no matter what program you use.

4 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.