Page 1 of 1

How to delete file

Posted: Sat Oct 21, 2023 3:48 pm
by bmld76
Hello,

I create a file in #PB_LocalStorage to test a record of a sqlite database. I don't find how to delete this file. The Purebasic command DELETE FILE don't exit in Spiderbasic.

Code: Select all

        *DatabaseBuffer = ExportDatabaseMemory(0)
        If CreateFile(0, FichierBase, @CreateFileCallback(), #PB_LocalStorage)
          WriteData(0, *DatabaseBuffer, 0, MemorySize(*DatabaseBuffer))
          CloseFile(0)
        EndIf
Thank for your help

Re: How to delete file

Posted: Wed Mar 19, 2025 4:29 pm
by akee
+1

Re: How to delete file

Posted: Wed Mar 19, 2025 6:03 pm
by Quin
+1

Re: How to delete file

Posted: Wed Mar 19, 2025 8:10 pm
by Peter
bmld76 wrote: Sat Oct 21, 2023 3:48 pmI don't find how to delete this file.
try this:

Code: Select all

Procedure DeleteFile(FileName$, Mode=0)
  
  ! LocalForage.removeItem("sbfs_" + v_filename$).then(function() {
  !   // Run this code once the file has been removed.
  Debug "The file was successfully deleted"
  ! }).catch(function(err) {
  !   // This code runs if there were any errors
  !   console.error(err);
  ! });
  
EndProcedure
P.S.: The code only works if at least one file command (e.g. CreateFile()) is present in the code. Only then will the LocalForage library of SpiderBasic be integrated into the code.