使用Python在Windows上获取非英语字符的简短路径

时间:2019-04-11 15:03:08

标签: python windows python-2.7 path

在Windows中,我尝试获取包含非英语字符的短路径(8.3 dos样式)。 以下代码(来自here)在_GetShortPathNameW()函数中返回错误(错误是:“找不到文件”)。

{
  field: 'employeeCode',
  sortable: true,
  filter: true,
  width: 200,
  colId: 'employeeCode',
  headerName : this.translate.get('navMenu.Home').subscribe((translated: string) => {

  return  translated;
   })
},

有什么主意吗?

1 个答案:

答案 0 :(得分:1)

由于Python 2.x没有为str使用抽象Unicode表示形式,因此这可能会错误地从Python 2.x字符串转换为Windows宽字符串。

相反,Python 2.x具有与unicode分开的str数据类型,并且您指定的纯字符串文字默认情况下不是Unicode。

使用Python 3.x可能是最好的选择,但是如果失败,使用显式unicode字符串可能会起作用:

print get_short_path_name(u"C:\\Users\\zvi\\Desktop\\אאאאא")

(请注意字符串前面的u前缀)