在Windows Vista操作系统中命名文件保留名称

Ah, the Compatibility Sins of the Father. Does anyone else think it's a hoot that you can't have a file called lpt1.png on your system? Or a folder called con?

啊,天父兼容性罪。 还有其他人认为您的系统上没有lpt1.png文件是一种麻烦吗? 还是名为con的文件夹?

There's a old story about the .NET CLR team - before they took over an entire Top-Level-Domain as their name, thereby effectively thwarting my own .ORG world domination strategy - where they wanted to call the successor to COM and COM++, "COM3."

关于.NET CLR团队,有一个古老的故事-在他们接管整个顶级域名作为他们的名字之前,从而有效地挫败了我自己的.ORG世界统治策略-他们想在此称呼COM和COM ++的后继者, COM3。

Apparently it didn't take long for them to realize that this was a sub-optimal name. Probably about this long:

显然,他们很快就意识到这是一个次优的名称。 大概这么长时间:

C:\Users\Scott>md com3
The directory name is invalid.

I'm still not clear, however, why this would be a problem in Vista. It's no doubt "compassionate conservative compatibilityism" (my new phrase of the day) on the part of Microsoft.

但是,我仍然不清楚为什么在Vista中这会成为问题。 微软无疑是“富有同情心的保守主义兼容性主义者” (我今天的新词)。

Of course, it's because the underlying Win32 APIs for opening a file STILL will accept "COM1" as a file name, as in:

当然,这是因为用于打开文件STILL的基础Win32 API将接受“ COM1”作为文件名,如下所示:

portHandle = CreateFile("COM1",
                  EFileAccess.GenericWrite,
                  EFileShare.None,
                  IntPtr.Zero,
                  ECreationDisposition.OpenExisting,
                  EFileAttributes.Device | EFileAttributes.Overlapped, IntPtr.Zero);

There's even a special way in Windows to refer to Serial Ports larger than COM9 in your code, like this -\\.\COM10.

Windows中甚至有一种特殊的方式可以在代码中引用大于COM9的串行端口,例如- \\。\ COM10

You see, they only choose to oppress us 9 times, for COM1 to COM9. From then on, we can live footloose and fancy-free.

您会看到,对于COM1到COM9,他们只选择压迫我们9次。 从那时起,我们可以过着自由奔放的生活。

C:\Users\Scott>md com9The directory name is invalid.

C:\Users\Scott>md com10

C:\Users\Scott>dir com10Volume in drive C is 70 GIGS SYSTEMVolume Serial Number is 98A2-64B2

Directory of C:\Users\Scott\com10

From MSDN:

从MSDN:

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 by an extension, for example, NUL.tx7.

不要使用以下保留的设备名称作为文件名:CON,PRN,AUX,NUL,COM1,COM2,COM3,COM4,COM5,COM6,COM7,COM8,COM9,LPT1,LPT2,LPT3,LPT4,LPT5 ,LPT6,LPT7,LPT8和LPT9。 还要避免使用这些名称后跟扩展名,例如NUL.tx7。

CLOCK$ is also a reserved device name.

CLOCK $也是保留的设备名称。

Good times.

美好时光。

翻译自: https://www.hanselman.com/blog/naming-a-file-a-reserved-name-in-the-windows-vista-operating-system

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值