系统长文件名与dos形式短文件名的相互转换
长文件名格式: C:\Program Files\Common Files\System\directdb.dll
DOS形式的短文件名 C:\PROGRA~1\COMMON~1\System\directdb.dll
有时编程时需要进行长短的转换
一、长文件名转短文件名,只需用一个函数就可以了
ExtractShortPathName('C:\Program Files\Common Files\System\directdb.dll')
二、短文件名转长文件名
首先定义函数
function GetLongPathName(Src, Dest: PChar; cch:DWord): DWord; stdcall; external 'Kernel32.dll' name 'GetLongPathNameA';
function ShortPathToLongPath(const AShortName: string): string;
var
sz: array[0..MAX_PATH - 1] of Char;
begin
FillChar(sz, SizeOf(sz), 0);
GetLongPathName(PChar(AShortName), sz, MAX_PATH);
Result := string(sz);
end;
使用
ShortPathToLongPath(’C:\PROGRA~1\COMMON~1\System\directdb.dll‘)
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.042369842529297 seconds