在Python中获取短path

如何在Windows中使用python获取文件的短path

我正在使用下面的代码,

#!/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 

Solutions Collecting From Web of "在Python中获取短path"

我想你正在寻找这个:

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

虽然您将需要win32api模块。

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

 import win32api long_file_name='C:\Program Files\I am a file' short_file_name=win32api.GetShortPathName(long_file_name)