How detect when a file "realy" is deleted (SOLVED)

Having this issue while doing the IFU, files are read from SD card, ready to start the update but i need to remove the files from SD card so the system is not picking these up after reboot.

                        // Close the files
                        filestreamApp.Close();
                        filestreamFw.Close();

                        // Dispose the objects
                        filestreamApp.Dispose();
                        filestreamFw.Dispose();

                        // Delete the files
                        File.Delete(rootDirectory.Name + "mfc.tca");
                        File.Delete(rootDirectory.Name + "firmware.ghi");

                        //Thread.Sleep(30000);

                        // Wait until processed by the file system before starting the update 
                        if (File.Exists(rootDirectory.Name + "mfc.tca"))
                        {
                            Debug.WriteLine("mfc.tca NOT deleted");
                        }

                        if (File.Exists(rootDirectory.Name + "firmware.ghi"))
                        {
                            Debug.WriteLine("firmware.ghi NOT deleted");
                        }

The File.Exist is returning false, but if i update and reboot the files are still on SD card.
If i put a break, wait for 60 seconds and then update and reboot the files are gone.

Question: How can i detect when the files are “Realy” deleted and not still in transition to be deleted?

Thx

You probably cannot ‘detect’ the state easily, but I suspect you are not calling ‘Flush()’ after the deletion.

Call FileSystem.Flush(sd.Hdc); to flush the memory-cached buffers to the SD card. On return from Flush, the SD card should be fully up to date.

See also : File System

1 Like

Thanks! Looks likes flush and unmount before update behaves reliable :+1: