Long
Filenames in Delphi
Converting a short filename:
- eg.: c:\progra~1\access~1\this_i~1.txt into a long
filename eg c:\programfiles\accessories\this is a long
filename.txt.
- There might be a better way, but this works:
- function AlternateToLFN(alternateName:
String): String;
- var temp: TWIN32FindData;searchHandle:
THandle;
- begin
- searchHandle :=
FindFirstFile(PChar(alternateName),
temp);
- if searchHandle <>
ERROR_INVALID_HANDLE then
- begin
- result :=
String(temp.cFileName);
- if result = '' then
- result :=
String(temp.cAlternateFileName);
- end
- else result := '';
- Windows.FindClose(searchHandle);
- end;
- function
AlternateToLongPath(alternateName:
String): String;
- var lastSlash: PChar;tempPathPtr:
PChar;
- begin
- result := '';
- tempPathPtr :=
PChar(alternateName);
- lastSlash :=
StrRScan(tempPathPtr,
'\');
- while lastSlash <>
nil do
- begin
- result := '\' +
AlternateToLFN(tempPathPtr)
+ result;
- if lastSlash <>
nil then
- begin
- lastSlash^ :=
char(0);
- lastSlash :=
StrRScan(tempPathPtr,
'\');
- end
- end;
- result := tempPathPtr +
result;
- end;
- begin
- {shortpath :=
'c:\progra~1\access~1\this_i~1.txt';
}
- longpath :=
AlternateToLongPath(shortpath);
- {if longpath = 'c:\program
files\accessories\this is a long
filename.txt' then
showmessage('It works.'); }
- end;
- Bryan Wilken: Bwilken@midusa.net
http://www.gcnet.com/bw/
see also gaSysTools functions!!!!