首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

TEMP环境变量有关问题

2012-07-29 
TEMP环境变量问题非常诡异,我在批处理中用了环境作为入参,本来环境变量TEMP应该为:C:\DOCUME~1\LIULIP~1\L

TEMP环境变量问题


非常诡异,我在批处理中用了环境作为入参,本来环境变量TEMP应该为:
C:\DOCUME~1\LIULIP~1\LOCALS~1\Temp>
而又个系统是这样的:
C:\DOCUME~1\LIULIP~1\Local Settings\Temp>

Local Settings有空格会导致入参解析有误,怎么设置才能成为LOCALS~1的形式?

[解决办法]
前后加入"呢
[解决办法]
查下短路径和长路径的转换吧

提供一个小工具,把长路径都转换成短路径,然后写入环境变量
[解决办法]
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364989(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364980(v=vs.85).aspx
[解决办法]
GetShortPathName
The GetShortPathName function obtains the short path form of a specified input path. 

DWORD GetShortPathName(
LPCTSTR lpszLongPath, // pointer to a null-terminated path string
LPTSTR lpszShortPath, // pointer to a buffer to receive the 
// null-terminated short form of the path
DWORD cchBuffer // specifies the size of the buffer pointed 
// to by lpszShortPath
);
 
Parameters
lpszLongPath 
Pointer to a null-terminated path string. The function obtains the short form of this path. 
lpszShortPath 
Pointer to a buffer to receive the null-terminated short form of the path specified by lpszLongPath. 
cchBuffer 
Specifies the size, in characters, of the buffer pointed to by lpszShortPath. 
Return Values
If the function succeeds, the return value is the length, in characters, of the string copied to lpszShortPath, not including the terminating null character.

If the function fails due to the lpszShortPath buffer being too small to contain the short path string, the return value is the size, in characters, of the short path string. You need to call the function with a short path buffer that is at least as large as the short path string. 

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

Remarks
When an application calls this function and specifies a path on a volume that does not support 8.3 aliases, the function fails with ERROR_INVALID_PARAMETER if the path is longer than 67 bytes.

The path specified by lpszLongPath does not have to be a fully qualified path or a long path. The short form may be longer than the specifed path. 

If the specified path is already in its short form, there is no need for any conversion, and the function simply copies the specified path to the buffer for the short path. 

You can set lpszShortPath to the same value as lpszLongPath; in other words, you can set the buffer for the short path to the address of the input path string. 

You can obtain the long name of a file from the short name by calling the FindFirstFile function. 

QuickInfo
Windows NT: Requires version 3.5 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also
File I/O Overview, File Functions, GetFullPathName, FindFirstFile 

 

热点排行
Bad Request.