Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: deletion of binary files

  1. #11

    deletion of binary files

    Since it comes with Delphi... just include it.

  2. #12

    deletion of binary files

    i sense that you are using fpc?

    Have you remembered to set up search paths?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #13

    deletion of binary files

    sry guys but this is all non-sense to me (sry for that ops: ) I am using Borland Turbo Pascal Version 0.7 and the unit I requested is not in my folders.

  4. #14
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2

    deletion of binary files

    Hi War Robe,

    Turbo Pascal... that takes me back... IIRC (I haven't used Turbo 7 since about 1996, so I could be wrong), it has no built in deleteFile or fileExists functions, so heres some I made a long time ago. I think these are right, as I said, its a long time since I used Turbo:-

    Code:
    type
      string255 = string[255];
    
    procedure deleteFile(fileName:string255);
    var
      f : file of byte;
      r : integer; (* Type of this could be wrong, adjust accordingly *)
    begin
      assign(f,filename);
      {$I-}
      erase(f);
      {$I+}
      r:=IOResult;
    end;
    
    function fileExists(fileName:string255):
    var
      f : file of byte;
      r : integer; (* Again, the type could be wrong *)
    begin
      assign(f,filename);
      {$I-}
      reset(f);
      {$I+}
      result:=(IOResult=0);
      {$I-}
      close(f);
      {$I+}
      r:=IOResult;
    end;
    I'm guessing, you've not used too many compiler directives yet, so heres a quick explanation of how these routines work without resulting in a run-time error.

    Normally, when an I/O error occurs (file doesn't exist when you open it with reset for example) the program will bomb out with an error dialogue. If that happens, these functions are useless, so we need to turn off I/O error checking temporarily. To do this, you use the {$I-} compiler directive. This turns off I/O error checking. When you do this, you MUST call IOResult to get the error code (if any) that was returned (IIRC, these codes are the same as the I/O Error message code that might normally be displayed). If you don't call IOResult, and you turn I/O error checking on with the {$I+} compiler directive, the next I/O operation will fail.

    So, in the case of deleteFile, we turn off error checking and use the 'erase' function. If the file exists, it is deleted. If not, nothing happens. We turn on error checking and then clear the I/O error result buffer by calling IOResult. In the case of fileExists, we turn off error checking, and attempt to open the file. If it exists, the function succeeds and IOResult should return 0. If it doesn't exist, the function fails and IOResult will return a non-zero value. We turn error checking on, check the IOResult value. And just in case we did open the file, we turn off error checking, close the file, turn error checking back on and then read IOResult again to clear the result buffer.

    I hope this helps.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  5. #15

    deletion of binary files

    thanku sooo much AthenaOfDelphi that really helped me out!! You literally saved my project!

    Thanks again,
    War Robe

  6. #16
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2

    deletion of binary files

    You're more than welcome hon, glad it helped.
    :: AthenaOfDelphi :: My Blog :: My Software ::

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •