Extracting the long path name (32-bit Windows style)
This function, when passed a short path name, will convert it to a long 32-bit Windows style path name. For example: ExtractLongPathName('C:\Thisis~1\Thisis~1.txt') will return 'C:\This is a directory\This is a file.txt'. To extract the short path name, see ExtractShortPathName().
functionExtractLongPathName(const PathName: string): string; { func to expand a Win3.1 style path name to a 32-bit Windows naming convention. } { If file doesn't exist, func will return an empty string. } var LastSlash, PathPtr: PChar;
function ExtractLongFileName(const FileName: string): string; var Info: TSHFileInfo; begin if SHGetFileInfo(PChar(FileName), 0, Info, SizeOf(Info), SHGFI_DISPLAYNAME) <> 0 then Result := string(Info.szDisplayName) else Result := FileName; end;
begin Result := ''; PathPtr := PChar(PathName); LastSlash := StrRScan(PathPtr, '\'); while LastSlash <> nildo begin Result := '\' + ExtractLongFileName(PathPtr) + Result; if LastSlash <> nilthen begin LastSlash^ := #0; LastSlash := StrRScan(PathPtr, '\'); end; end; Result := PathPtr + Result; end;