在python中获取短路径 [英] Getting short path in python

查看:157
本文介绍了在python中获取短路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Windows中使用python获取文件的短路径?

How do I obtain the short path of a file in Windows using python ?

我正在使用以下代码,

#!/usr/bin/python
import os
import sys
fileList = []
rootdir = sys.argv[1]
for root, subFolders, files in os.walk(rootdir):
    for file in files:
        fileList.append(os.path.join(root,file))
for File in fileList:
    print File

推荐答案

我想您正在寻找的是

http://docs.activestate.com/activepython/2.5/pywin32/win32api__GetShortPathName_meth.html

尽管您将需要使用win32api模块.

Although you will need the win32api module for this.

另请参阅以下链接: http://mail.python.org/pipermail/python-win32 /2006-May/004697.html

Also see this link: http://mail.python.org/pipermail/python-win32/2006-May/004697.html

这篇关于在python中获取短路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆