I have a Flexy 201 with firmware version 14.2s0. I am using the following function to delete the oldest file saved to an external SD card. The “ls” command is supposed to sort the contents of the directory based on file creation. For testing purposes I am creating 10 text files and then attempting to delete the first one created. The files are only listed in the correct order if they all created within the same hour. Once I have files that are created in different hours, the “ls” command no longer works correctly. The “ls” command seems to list the files at random. For example, if I create 10 files between 9:00am and 9:59am, they will be listed correctly with the newest file at index 0 and the oldest file at index 9. However, if I create a file at 10:01am, the list is no longer listed in the order of creation date.
Am I using the FS “ls” command wrong? Is there a special way I need to be creating files? Does the FS “ls” command work correctly with SD cards?
FUNCTION delete_file%($directory$, $NumOfFiles%)
file_count% = FS “count”, $directory$
PRINT "File Count "; file_count%
FOR $i% = 0 To file_count% - 1
ls$ = FS “ls”, $directory$, $i%
PRINT “File#”; $i%; " = "; ls$
NEXT $i%
IF (file_count% >= $NumOfFiles%) THEN
ls$ = FS “ls”, $directory$, file_count% - 1
//ls$ = FS “ls”, $directory$, 0
PRINT "Delete File = "; ls$
fileString$ = $directory$ + ls$
FS “rm”, fileString$
ENDIF
file_count% = FS “count”, $directory$
$delete_file% = file_count%
ENDFN