Hacker News new | ask | show | jobs
by adrianpike 5304 days ago
Can somebody more familiar with the Windows environment explain why prn.h is an "invalid file name"?

edit:// thanks all! :)

5 comments

It's reserved for compatibility:

"Do not use the following reserved device names for the name of a file:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended."[1]

[1] http://msdn.microsoft.com/en-us/library/windows/desktop/aa36...

I once saw some interesting behavior on a Windows 95 machine - my brother printed a drawing for a convention to a file. The printer was a HP LaserJet with plug in module that enabled Postscript. He named the file "con" and when he hit OK on the print dialog the entire screen buffer (over the windowing interface) started filling with Postscript.
Windows tries to prevent you naming a file "con". I once renamed a text file con in Win95; using a raw disk editor to change the file entry and it did this too - every time I saved text in the file it would write it console/DOS style to the screen.
We're encountered this issue when dealing with ETF tickers. We use Linux but a 3rd-party redistributor was on Windows; the reports we created had file names in the form <TICKER>.pdf and, what would you know, PRN.pdf caused all sorts of trouble for them...
You can't have files named like the old DOS devices: CON, LPT, AUX, PRN etc. This is originaly due to CP/M backwards compatibility, it didn't have directories so magic files were udde to pipe stuff to printers and other devices.
"finally the behavior of the window filesystem is so incredibly broken that well they should really fix it I guess."

Ha. Just allow "prn", I'm sure that won't have any side effects.

PC-DOS inherited it from CP/M 80. Windows was built at first on top of it and then replaced it in stages. I have no idea why would this still be present in the current codebase. It would probably be easier just to fix the filesystem.
There's countless batch files that rely on NUL (including with extensions, usually because some other batch file is appending the extension). Most of the other ones could probably be safely removed, but it would still run contrary to Microsoft's policy of not breaking backwards compatibility unless absolutely necessary.
prn is for printer and there are many such reserved device names

http://en.wikipedia.org/wiki/Device_file#Device_files