如果有这样一个目录: c:\windows\media\temp\abc\sound\chime.wav 我希望它能缩短成: c:\windows\..\sound\chime.wav 如何写程序呢?
function shortenfilename(s : string) : string; var drive,curdrive : string[2]; dir,curdir : string[80]; name : string[20]; ext : string[5]; i : byte; begin for i:=1 to length(s) do s[i]:=upcase(s[i]); s:=fexpand(s); fsplit(s,dir,name,ext); drive:=copy(dir,1,2); dir:=copy(dir,4,length(dir)-3); getdir(0,curdir); curdrive:=copy(curdir,1,2); curdir:=copy(curdir,4,length(curdir)-3)+‘\'; if drive=curdrive then begin if copy(dir,1,length(curdir))=curdir then begin i:=length(curdir); if length(dir)<>i then dir:=dir+‘\'; shortenfilename:=copy(dir,i+1,length(dir)-i-1)+name+ext; end else shortenfilename:=copy(s,3,length(s)-2); end else shortenfilename:=s; end;
|