获取路径的简称 [英] Get Short Name of Path

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

问题描述

获取任何给定路径的简称,我已经使用下面的代码尝试了这个,但它提供了与长路径相同的短路径。



CString sFilePath = _T(D:\\ kn);

TCHAR szFilePath [100] = {0};

GetShortPathName(sFilePath,szFilePath,sizeof(szFilePath));

printf(%s \ n,sFilePath);

printf (%s,szFilePath);

Get the short name of any given path, I have already tried this using the below code but it gives same short path as long path.

CString sFilePath = _T("D:\\kn");
TCHAR szFilePath[100] = {0};
GetShortPathName(sFilePath, szFilePath, sizeof(szFilePath));
printf("%s\n", sFilePath);
printf("%s", szFilePath);

推荐答案

hi,

短路径不仅在路径冗长时,而且在它之间有空格,如:C:\Temp \New Folder。所以这里的短路径将是C:\Temp \New~1。



您没有使用正确的路径进行测试。尝试使用一些长路径名称或在两者之间留出空格。



希望这会有所帮助。

Short paths are preferred not only when the path is lengthy but also when it has spaces in between like : C:\Temp\New Folder . So here the short path will be something like C:\Temp\New~1.

You are not testing with the correct path. Try with with some long path name or give a space in between .

hope this helps.


来自MSDN GetShortPathName [ ^ ]:

From MSDN GetShortPathName[^]:
Quote:

如果指定的路径已经是短格式并且不需要转换,则该函数只复制指定的路径到lpszShortPath参数指定的缓冲区。

If the specified path is already in its short form and conversion is not needed, the function simply copies the specified path to the buffer specified by the lpszShortPath parameter.

您的示例路径D:\ kn已经是缩写形式。

Your example path "D:\kn" is already in the short form.


快速搜索找到了这个讨论。 http://stackoverflow.com/questions/843843/getshortpathname-unpredictable-results [ ^ ]



看起来GetShortPathname存在问题并不总是提供预期结果。有关可能的解决方法,请参阅上述讨论中提供的解决方案。
A quick search found this discussion. http://stackoverflow.com/questions/843843/getshortpathname-unpredictable-results[^]

Apperently there is an issue with GetShortPathname not always delivering the expected results. Refer to the solution presented in the abovementioned discussion for a possible workaround.


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

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