Re:D2: Long filename to Short Conversion
Quote
"Mark Edwards" <m...@creativity.demon.co.uk> wrote:
Yea try this code i came up with when i had tha same problem
the lfntoalternate function i got out of the swags, the rest is mine
you can feed a whole structure + filename example:
function lsfilename('c:\windows\hello matey\this is a
test\ok.bb.cc.exe');
will return the short version of the whole line! :)
function LFNToAlternate(LongName: String): String;
var temp: TWIN32FindData;
searchHandle: THandle;
begin
searchHandle := FindFirstFile(PChar(LongName), temp);
if searchHandle <> ERROR_INVALID_HANDLE then
result := String(temp.cALternateFileName)
else
result := '';
Windows.FindClose(searchHandle);
end;
function lsfilename(name:string):string;
var
chstr:array [0..300] of char;
countn,partcount:integer;
newstr,part:string;
ch:char;
ignore:boolean;
test:string;
begin
part:='';newstr:=''; partcount:=0; ignore:=false;
strpcopy(chstr,name);
for countn:=0 to length(name)-1 do
begin
ch:=chstr[countn];
if (ch='\') or (ch=':') then
begin
if partcount>7 then
begin
newstr:=newstr+LFNToAlternate(newstr+part);
end else
begin
newstr:=newstr+part;
end;
if ch='\' then
begin
newstr:=newstr+'\';
end else
begin
newstr:=newstr+':';
end;
part:=''; partcount:=0; ignore:=false;
end else
begin
partcount:=partcount+1;
part:=part+ch;
end;
end;
if length(part)>0 then
begin
test:=LFNToAlternate(newstr+part);
if length(test)>0 then
begin
lsfilename:=newstr+test;
end else
begin
lsfilename:=newstr+part;
end;
end else
begin
lsfilename:=newstr;
end;
end;
!Seeper!
j...@es.co.nz