Erase

From Delphi Pascal wiki
Jump to navigation Jump to search

Erases an external file.

Declaration
procedure Erase(var F);
Target
Windows, Real, Protected
Remarks
F is a file variable of any file type. The external file associated with F is erased.
With {$I-}, IOResult returns 0 if the operation was successful. Otherwise, it returns a nonzero error code.
Restrictions
Never use Erase on an open file.
See Also
Rename


Sample Code

{Erase.PAS}
{Sample code for Erase procedure. }

{ For Windows: }
{ uses WinCrt; }

var
 F:  file;
 Ch: Char;
begin
 { Get file to delete from command line }
 Assign(F, ParamStr(1));
 {$I-}
 Reset(F);
 {$I+}
 if IOResult <> 0 then
   Writeln('Cannot find ', ParamStr(1))
 else
 begin
   Close(F);
   Write('Erase ', ParamStr(1), '? ');
   Readln(Ch);
   if UpCase(CH) = 'Y' then
     Erase(F);
 end;
end.