VinceLomba
VinceLomba

Reputation: 428

How to delete file .bat with pascal

How can I delete files using pascal? (Not only .txt files) Example: I have a .bat file that have the directory C:\Settings\BATCH.bat . How can I delete it?

Delete('C:\Settings\BATCH.bat');

Or something like that? What do I have to do?

Upvotes: 0

Views: 922

Answers (1)

You can try the Erase command:

Program deletefile;

{ Program to demonstrate the Erase function. }

Var F : Text;

begin
  { Create a file with a line of text in it}
  Assign (F,'test.txt');
  Rewrite (F);
  Writeln (F,'Try and find this when I''m finished !');
  close (f);
  { Now remove the file }
  Erase (f);
end.

You have to assign the file but don't open it (with Reset or Rewrite). For more information visit the following doc page: http://www.freepascal.org/docs-html/rtl/system/erase.html

Upvotes: 1

Related Questions