~请问,如何将一个长文件名转换为8.3格式???

时间:2022-11-22 06:36:47
偶在用CInternetSession的OpenURL函数时,
发现不能使用"file://C:/Documents and Settings/Administrator/Desktop/aaa.txt"
这样的文件名,
而改为"file://D:/temp/aaa.txt"就行,
偶想应该是长文件名的问题,
特向各位求教,谢谢!

5 个解决方案

#1


应该不是太长的原因吧,会不会空格的问题?

#2


是不是文件名中空格的问题。

#3


GetShortPathName

The GetShortPathName function retrieves the short path form of the specified path.


DWORD GetShortPathName(
  LPCTSTR lpszLongPath,
  LPTSTR lpszShortPath,
  DWORD cchBuffer
);

Parameters
lpszLongPath 
[in] Pointer to a null-terminated path string. The function retrieves the short form of this path. 
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Windows Me/98/95:  This string must not exceed MAX_PATH characters.
lpszShortPath 
[out] Pointer to a buffer to receive the null-terminated short form of the path specified by lpszLongPath. 
cchBuffer 
[in] Size of the buffer pointed to by lpszShortPath, in TCHARs. 
Return Values
If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpszShortPath, not including the terminating null character.

If the lpszShortPath buffer is too small to contain the path, the return value is the size of the buffer, in TCHARs, required to hold the path. Therefore, if the return value is greater than cchBuffer, call the function again with a buffer that is large enough to hold the path.

If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError.

#4


如果有空格,就加上引号
"\"file://C:/Documents and Settings/Administrator/Desktop/aaa.txt\""

#5


呵呵,谢谢各位,问题解决,结账!

#1


应该不是太长的原因吧,会不会空格的问题?

#2


是不是文件名中空格的问题。

#3


GetShortPathName

The GetShortPathName function retrieves the short path form of the specified path.


DWORD GetShortPathName(
  LPCTSTR lpszLongPath,
  LPTSTR lpszShortPath,
  DWORD cchBuffer
);

Parameters
lpszLongPath 
[in] Pointer to a null-terminated path string. The function retrieves the short form of this path. 
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Windows Me/98/95:  This string must not exceed MAX_PATH characters.
lpszShortPath 
[out] Pointer to a buffer to receive the null-terminated short form of the path specified by lpszLongPath. 
cchBuffer 
[in] Size of the buffer pointed to by lpszShortPath, in TCHARs. 
Return Values
If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpszShortPath, not including the terminating null character.

If the lpszShortPath buffer is too small to contain the path, the return value is the size of the buffer, in TCHARs, required to hold the path. Therefore, if the return value is greater than cchBuffer, call the function again with a buffer that is large enough to hold the path.

If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError.

#4


如果有空格,就加上引号
"\"file://C:/Documents and Settings/Administrator/Desktop/aaa.txt\""

#5


呵呵,谢谢各位,问题解决,结账!