Python:将Windows路径转换为DOS路径

时间:2019-10-31 15:57:55

标签: python windows path

我正在寻找一种在Python中将完整的Windows“ LFN样式”路径名转换为DOS路径名的方法。 请注意,我正在寻找答案“反斜杠空格”。 这是一个示例:

'C:\Users\Fred\Foo\Long directory name with many spaces\long filename that also has many spaces.txt'

...将成为...

'C:\Users\Fred\Foo\LONGDI~1\LONGFI~1.TXT'

在cygwin(或Git Bash)中,可以使用命令cygpath -da "$path"完成。我原本希望在模块os.path或模块pathlib中找到某些东西……似乎不在这两个地方。

0 个答案:

没有答案