python win32 filename length workaround

前端 未结 2 860
盖世英雄少女心
盖世英雄少女心 2020-12-17 21:22

I have found out that you can\'t open(filepath) when filepath length is greater than 255 characters even if the filename itself is 10 characters long (the remai

相关标签:
2条回答
  • 2020-12-17 22:01

    The most general approach to this is to prefix the path with \\\\?\\ (reference). Be aware that this disables certain pre-processing on the path, but nothing major IMO.

    Also I can note that on 32-bit Windows Server 2003 with Python 2.7 I had to use prefixed Unicode path (u"\\\\\\\\?\\\\" prefix or ur"\\\\?\\") since (as mentioned in reference) non-Unicode API functions may still be limited to MAX_PATH length even though the prefix is used.

    e.g., ur"\\\\?\\c:\temp\....\abc.txt"

    0 讨论(0)
  • 2020-12-17 22:22

    A Windows OS level solution is to use the DOS SUBST command to define a pseudo drive at a particular directory.

    SUBST Q: C:\really\long\path\name\full\of\sub\directories
    

    Then you can access the files in that directory as Q:filename.

    0 讨论(0)
提交回复
热议问题