FolderItem looses file extension when filename is prn.tfx

I ran into a very strange issue with the FolderItem.

  Dim f as new FolderItem()
  f = f.Child("prn.tfx")
  msgbox f.Name

The output of the above msgbox should be “prn.tfx”, but it shows “prn”?

Change the filename to anything else other than prn.tfx and it works as expected. Does anyone know if the filename “prn.tfx” has any special meaning?

I’m running this code on Windows 10.

I might have expected to see this if you used .DisplayName, which I understand respects the preferences of Explorer
(Hide extensions for known file types)

When you say ‘change the name to anything other than’… do you mean pot.tfx works?
If so, does prn.wibble show the same problem?
And if it does, it will be because PRN is being considered like a device name … its an old shorthand for the printer device.

I’ve just tested and both pot.tfx and prn.wibble works as expected. I only have the issue with prn.tfx.

This is a very strange issue indeed, but I suspect you are right in that “prn.tfx” is some sort of reserved file on windows?

There can be a difference between FolderItem .DisplayName and .Name ?

I learn something more today :wink:

pot can be in the licencious words list (check with the BBC…)

Isn’t prn a special name to refer to printer?

I’m not sure.

It is strange though that “prn.wobble” has no issues, but “prn.tfx” breaks?

If you try to create a file with that name in the Windows Explorer the system will say “The specified device name is invalid.”
When you use the .wobble extension you are not relying on the old 8.3 subsystem of filenames and thus can create the file.
Correction: you cannot create the file.

Thank you for confirming this Mattias.

I’ve coded in a workaround in my app to simply just avoid using the filename prn.tfx.

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

Ah, thanks Norman. This explains the issue.

From the article these are all the names that should be avoided:

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. 

And they recomand (!) the use of a leading dot in item names.

WARNING: Doing that will set your file as INVISIBLE if you move it to macOS.

Thank you for the heads up Emile.

Where?

Using a filename of PRN with any three-letter extension should result in an error. The reason being that PRN is a MS-DOS device name for the default system printer.

In the old days we could open “PRN” as a filename and write text data to it, that data would then be printed.

Using more than three letters (like .wobble) for the extension changes the format of the 8.3 filename created on the disk, most likely PRN~1.WOB, which is allowed.