如何把DOS下的短文件名转换为长文件名?(50分)

  • 主题发起人 主题发起人 lfg
  • 开始时间 开始时间
L

lfg

Unregistered / Unconfirmed
GUEST, unregistred user!
如何把DOS下的短文件名转换为长文件名?
(例如:C:/Mydocu~1/ok.txt ---> C:/Mydo
cuments/ok.txt)
 
GetlongPathName()
try
 
我现在去写源代码,下次来给你
 
如果你只知道文件名是C:/Mydocu~1/ok.txt 根本不可能把它转换为C:/Mydo
cuments/ok.txt!
 
function GetFullPathName( const Path : String ): String;
var
nBufferLength : DWORD;
// size, in characters, of path buffer
lpBuffer : PChar;
// address of path buffer
lpFilePart : PChar;
// address of filename in path
begin
nBufferLength := MAX_PATH + 1;
GetMem( lpBuffer, MAX_PATH + 1 );
try
if Windows.GetFullPathName( PChar( Path ), nBufferLength, lpBuffer, lpFilePart ) <> 0 then
Result := lpBuffer
else
Result := 'ERROR';
finally
FreeMem( lpBuffer );
end;
end;
 
摘自MSDN October 2001
-----------------------------------------
GetLongPathName
The GetLongPathName function converts the specified path to its long form.
If no long path is found, this function simply returns the specified name.
DWORD GetLongPathName(
LPCTSTR lpszShortPath, // file name
LPTSTR lpszLongPath, // path buffer
DWORD cchBuffer // size of path buffer
);
Parameters
lpszShortPath
[in] Pointer to a null-terminated path to be converted.
Windows 2000: In the ANSI version of this function, the name is limited to
MAX_PATH characters. To extend this limit to nearly 32,000 wide characters,
call the Unicode version of the function and prepend "//?/" to the path.
For more information, see File Name Conventions.
Windows 98: This string must not exceed MAX_PATH characters.
lpszLongPath
[out] Pointer to the buffer to receive the long path. You can use the same
buffer you used for the lpszShortPath parameter.
cchBuffer
[in] Specifies the size of the buffer, in TCHARs.
Return Values
If the function succeeds, the return value is the length of the string copied
to the lpszLongPath parameter, in TCHARs. This lengthdo
es not include the
terminating null character.
If lpszLongPath is too small, the function returns the size, in TCHARs, of
the buffer required to hold the long path.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.
Requirements
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 98.
Header: Declared in Winbase.h;
include Windows.h.
Library: Use Kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows 2000.
See Also
File I/O Overview, File I/O Functions, GetFullPathName, GetShortPathName
Built on Wednesday, July 19, 2000Requirements
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 98.
Header: Declared in Winbase.h;
include Windows.h.
Library: Use Kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows 2000.
See Also
File I/O Overview, File I/O Functions, GetFullPathName, GetShortPathName
 
function GetLongFileName(Const FileName : String) : String;

var
aInfo: TSHFileInfo;

begin

if SHGetFileInfo(PChar(FileName),0,aInfo,Sizeof(aInfo),SHGFI_DISPLAYNAME)<>0 then

Result:= String(aInfo.szDisplayName)
else

Result:= FileName;

end;

 
多人接受答案了。
 

Similar threads

回复
0
查看
1K
不得闲
S
回复
0
查看
896
SUNSTONE的Delphi笔记
S
S
回复
0
查看
873
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部