File_DeleteFile(pFileName), Bit
pFileName: The name of the file to delete, which can be up to 12 characters in length (including the file extension and dot). The allowed format is a string of the form String * 12.
Return Values:
1 (Success): The file was successfully deleted from the SD card.
0 (Error): An error occurred during the deletion process, such as a read/write error.
Delete a File from the SD Card
The File_DeleteFile() command allows you to delete an existing file on the SD card. Before you can delete a file, you must ensure the file is either closed or flushed to prevent data corruption.
How it Works:
• File Deletion: File_DeleteFile() removes the specified file from the SD card. It updates the FAT (File Allocation Table) and the corresponding clusters used by the file.
• File Closure: Before calling File_DeleteFile(), the file should be closed with File_Close() or flushed with File_Flush(). This ensures that there are no open handles or pending writes to the file, which could lead to data corruption.
• FAT Update: After deletion, the FAT is updated, and the space occupied by the file is marked as free for reuse.
Example:
File_DeleteFile("Text.txt")
Notes:
• File Closure: Always close or flush a file before deleting it to avoid corruption.
• Use Case: This command is useful for managing files on the SD card, allowing you to remove files when they are no longer needed.
• File Integrity: If the file is still open, the deletion may fail, and you might encounter errors. Ensure proper closure or flushing before deletion.
TftSetUp(0) 'Set screen TftResetScreen(BLACK) 'Reset screen TftSetSndFont(0,0) 'Set Font0 While File_Init() <> cErrOK : Wend 'Initialize SD Card TftPrintSndString("Sd Initialization OK",1,0,0,1,GREEN,BLACK,0) 'Confirm Initialize SD Card If File_DeleteDir("stop") = 1 Then TftPrintSndString("Delete stop OK",1,0,2,1,GREEN,BLACK,0) 'stop folder deleted (expected) Else TftPrintSndString("Delete stop NO",1,0,2,1,GREEN,BLACK,0) 'stop folder not deleted EndIf If File_DeleteDir("start") = 1 Then TftPrintSndString("Delete start OK",1,0,3,1,GREEN,BLACK,0) 'start folder deleted Else TftPrintSndString("Delete start NO",1,0,3,1,GREEN,BLACK,0) 'start folder not deleted (expected) EndIf If File_DeleteFile("gif.txt") = 1 Then TftPrintSndString("Delete gif.txt OK",1,0,4,1,GREEN,BLACK,0) 'gif.txt deleted (expected) Else TftPrintSndString("Delete gif.txt NO",1,0,4,1,GREEN,BLACK,0) 'gif.txt not deleted EndIf If File_DeleteFile("test.log") = 1 Then TftPrintSndString("Delete test.Log OK",1,0,5,1,GREEN,BLACK,0) 'test.Log deleted Else TftPrintSndString("Delete test.Log NO",1,0,5,1,GREEN,BLACK,0) 'test.Log not deleted (expected) EndIf |
|
Created with the Personal Edition of HelpNDoc: Don't Let Unauthorized Users View Your PDFs: Learn How to Set Passwords