Recent

Author Topic: Delete a file from an Lazarus/FPC app  (Read 1281 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 437
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Delete a file from an Lazarus/FPC app
« on: November 18, 2023, 04:24:51 pm »
Simple question but can't find in any of my docs on Lazarus on how to delete a file.  I'm programming on a Windows computer and want to export the data from a database (TDbf) table, delete the table and it's index/memo files, then recreate the table and indexes then import the CSV export data.
I know how to do all that except delete the files with pascal code.

jamie

  • Hero Member
  • *****
  • Posts: 7610
Re: Delete a file from an Lazarus/FPC app
« Reply #1 on: November 18, 2023, 04:27:42 pm »
deleteFile ?

Just specify the full path to it and make sure the file isn't in use at the time.
The only true wisdom is knowing you know nothing

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Delete a file from an Lazarus/FPC app
« Reply #2 on: November 18, 2023, 04:39:42 pm »
Be mindful and excellent with each other.
https://github.com/cpicanco/

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 437
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Delete a file from an Lazarus/FPC app
« Reply #3 on: November 18, 2023, 08:55:56 pm »
Thanks, Delete a file from the file system.


function DeleteFile(const FileName: RawByteString):Boolean;

Description: DeleteFile deletes file FileName from disk. The function returns True if the file was successfully removed, False otherwise.  On error, False is returned.

So, to delete a Dbf file named Appointments.dbf from a file located on 'C:\Documents\Software Development\PMS Project\PMS Data\'

if DeleteFile(C:\Documents\Software Development\PMS Data\Appointments.dbf) = True then
  CreateNewAppointments.dbf table code
else
  Error statement;

Correct?

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 437
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Delete a file from an Lazarus/FPC app
« Reply #4 on: November 18, 2023, 09:06:02 pm »
DeleteFile('C:\Documents\Software Development\PMS Project\PMS Data\Appointments.dbf');

More correct ... Thanks

 

TinyPortal © 2005-2018