Using LittleFs/ Esp32.
Trying to clear a directory with:
Dim fs As LittleFS 'in Process_Globals
For Each f As File In fs.ListFiles("/")
fs.Remove(f.Name)
Next
does not delete the files and gives the error like:
E (29523) esp_littlefs: Failed to unlink path "/Image30.jpg". Has open FD.
for each file.
Am I going something wrong? Or is this a bug? Or.....?
This code works but will have problems if there are more than 50 (or whatever value is set) files:
Dim FileString(50) As String
Dim i As Int = 0
For Each f As File In fs.ListFiles("/")
FileString(i) = BC.StringFromBytes(f.name)
i = i + 1
Next
For n = 0 To i -1
fs.Remove(FileString(n))
Next
Modifying it to the following partially works but one delete fails at each exit/ loop so isn't useable:
Dim FileString(5) As String
Dim i As Int = FileString.Length
Do While i = FileString.length
i = 0
For Each f As File In fs.ListFiles("/")
FileString(i) = BC.StringFromBytes(f.name)
i = i + 1
If i > 4 Then Exit
Next
For n = 0 To i -1
fs.Remove(FileString(n))
Next
Loop
Is there a better way?
Thanks