con.py 这个文件是有特殊含义吗?

2022-04-29 21:17:23 +08:00
 css3

linux服务器上随便手了一个con.py文件, 编写完,准备从windowsscp 过来, 发现竟然死活无法发送::/code/con.py: truncate: No error , 又尝试从xftp直接从远程拉,也直接显示错误, 然后把名称改了,竟然能正常发送了, 这是为啥,太好奇了

1758 次点击
所在节点    程序员
5 条回复
yuzo555
2022-04-29 21:22:44 +08:00
设备名称,类似的有 nul 、aux 、prn 、com1 、com2
learningman
2022-04-29 21:23:18 +08:00
con 在 Windows 上是 console 设备的名字
但是 con.py 应该是没问题的吧。。。
yzwduck
2022-04-29 21:43:08 +08:00
@learningman CON.PY 也一样会有兼容性问题,除非加上 \\?\ 前缀。
文档 https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file

Old New Things 写过一篇解释 "What's the deal with those reserved filenames like NUL and CON?"
https://devblogs.microsoft.com/oldnewthing/20031022-00/?p=42073
learningman
2022-04-29 21:45:38 +08:00
@yzwduck 看到了
Because it turns off automatic expansion of the path string, the "\\?\" prefix also allows the use of ".." and "." in the path names, which can be useful if you are attempting to perform operations on a file with these otherwise reserved relative path specifiers as part of the fully qualified path.

Many but not all file I/O APIs support "\\?\"; you should look at the reference topic for each API to be sure.

Note that Unicode APIs should be used to make sure the "\\?\" prefix allows you to exceed the MAX_PATH
MiketsuSmasher
2022-04-30 07:34:27 +08:00
不错,Windows 真够屎山

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/850122

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX