V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
css3
V2EX  ›  程序员

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

  •  
  •   css3 · Apr 29, 2022 · 2382 views
    This topic created in 1467 days ago, the information mentioned may be changed or developed.

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

    5 replies    2022-04-30 07:34:27 +08:00
    yuzo555
        1
    yuzo555  
       Apr 29, 2022
    设备名称,类似的有 nul 、aux 、prn 、com1 、com2
    learningman
        2
    learningman  
       Apr 29, 2022
    con 在 Windows 上是 console 设备的名字
    但是 con.py 应该是没问题的吧。。。
    yzwduck
        3
    yzwduck  
       Apr 29, 2022   ❤️ 1
    @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
        4
    learningman  
       Apr 29, 2022
    @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
        5
    MiketsuSmasher  
       Apr 30, 2022
    不错,Windows 真够屎山
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   987 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 23:21 · PVG 07:21 · LAX 16:21 · JFK 19:21
    ♥ Do have faith in what you're doing.