[fpc-pascal]ExtractFileDir ?
Iván Montes
senbei at terra.es
Thu Feb 13 00:57:15 CET 2003
According to the docs
http://www.freepascal.org/docs-html/units/node23.html#SECTION002366000000000
000000
"ExtractFileDir returns only the directory part of FileName, not including
a
driveletter."
But it does return the driveletter, so either the docs are mistaken or the
RTL.
If the docs are right here there is a function that will return only the
dir, removing
any drive letter.
ie:
c:\testdir\test\file.ext => \testdir\test
c:\testdir\ => \testdir
c:testdir\ => testdir
\testdir\test.exe => \testdir
[objpas\fina.inc]
function ExtractFileDir(const FileName: string): string;
var i,j: longint;
begin
if FileName[2]=':' then j:=3
else j:=1;
I := Length(FileName);
while (I > 0) and not (FileName[I] in ['/', '\', ':']) do Dec(I);
if (I > j) and (FileName[I] in ['\', '/']) and
not (FileName[I - 1] in ['/', '\', ':']) then Dec(I);
Result := Copy(FileName, j, I-j+1);
end;
HTH, ivan
More information about the fpc-pascal
mailing list