Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:18:49+00:00 2026-06-04T21:18:49+00:00

Does Rewrite clear file contents of existing file or does it delete it and

  • 0

Does Rewrite clear file contents of existing file or does it delete it and create a new one?
I have a text file in my app.exe folder which I need to clear. Any example?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:18:50+00:00Added an answer on June 4, 2026 at 9:18 pm

    From the Delphi XE2 documentation, topic Rewrite – read the last quoted paragraph:

    Creates a new file and opens it.

    In Delphi code, Rewrite creates a new external file with the name assigned to F.

    F is a variable of any file type associated with an external file using AssignFile. RecSize is an optional expression that can be specified only if F is an untyped file. If F is an untyped file, RecSize specifies the record size to be used in data transfers. If RecSize is omitted, a default record size of 128 bytes is assumed.

    If an external file with the same name already exists, it is deleted and a new empty file is created in its place.

    From the same documentation, link at the bottom of page for System.Rewrite, modified to use your app’s folder:

    procedure TForm1.Button1Click(Sender: TObject);
    var 
      F: TextFile;
      AppDir: string;
    begin
      // Instead of ParamStr(0), you can use Application.ExeName
      // if you prefer
      AppDir := ExtractFilePath(ParamStr(0)); 
      AssignFile(F, AppDir + 'NEWFILE.$$$');
      Rewrite(F);  // default record size is 128 bytes
      Writeln(F, 'Just created file with this text in it...');
      CloseFile(F);
      MessageDlg('NEWFILE.$$$ has been created in the ' + AppDir + ' directory.',
        mtInformation, [mbOk], 0, mbOK);
    end;
    

    You should know, though, that Rewrite is outdated and doesn’t support Unicode. You should be using more modern methods to read and write files like TFileStream or TStringWriter (or even the simple solution of TStringList).

    var
      SL: TStringList;
      AppDir: string;
    begin
      AppDir := ExtractFilePath(ParamStr(0));
      SL := TStringList.Create;
      try
        SL.Add('Just created file with this text in it...');
        // Add more lines here if needed, and then only save once
        SL.SaveToFile(AppDir + 'NEWFILE.$$$');
        MessageDlg('NEWFILE.$$$ has been created in the ' + AppDir + ' directory.',
          mtInformation, [mbOk], 0, mbOK);
      finally
        SL.Free;
      end;
    end;
    

    Note that you cannot use TStrings; it’s an abstract class. You need to use one of it’s descendants instead (TStringList is the one used most often).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to rewrite my robots.txt for all domains but main one (I have
Does anyone have experience using the URL Rewrite Module (see here )? Can it
When git does a commit it rewrites binary files with something similar to rewrite
I'm having rewrite issues. http://test.bradp.com/drupal/Crocodile-Style/1 works OK. http://test.bradp.com/drupal/Crocodile-Style/ DOES NOT WORK. Apache throws a
When you turn on the nginx rewrite log with rewrite_log on; , where does
Does C# allow hashtables to be populated in one-line expressions? I am thinking of
Does anyone have a nice solution for GalleryView when I want to display photos
I have a solution but it is one that I know is not the
I have a page, called foo.aspx and i d like to rewrite the url
We have a PHP app with a dynamic URL scheme which requires characters to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.