R RJB Active Member Licensed User Longtime User Nov 1, 2022 #1 Using LittleFs/ Esp32. Trying to clear a directory with: B4X: Copy 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: B4X: Copy 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: B4X: Copy 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
Using LittleFs/ Esp32. Trying to clear a directory with: B4X: Copy 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: B4X: Copy 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: B4X: Copy 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
C candide Active Member Licensed User Longtime User Nov 1, 2022 #2 with a google search on "esp_littlefs: Failed to unlink path Has open FD" you will see similar issues found under arduino. (files are seen open at low level) possible this one will help : Recursive delete of directory does not work as expected on LittleFS Deltree.ino.txt The attached Arduino sketch compiled for ESP32 fails to recursively delete a directory. When executed on an SD_MMC FAT filesystem the directory is succesfully removed. When built with debug the following messages are show... www.giters.com Upvote 0
with a google search on "esp_littlefs: Failed to unlink path Has open FD" you will see similar issues found under arduino. (files are seen open at low level) possible this one will help : Recursive delete of directory does not work as expected on LittleFS Deltree.ino.txt The attached Arduino sketch compiled for ESP32 fails to recursively delete a directory. When executed on an SD_MMC FAT filesystem the directory is succesfully removed. When built with debug the following messages are show... www.giters.com
R RJB Active Member Licensed User Longtime User Nov 1, 2022 #3 Thanks. I had seen that. It seems to be suggesting that you close the file but there doesn't seem to be a way to do that in B4r. FS.close doesn't do it and there doesn't appear to be a way to close a file by name. Am I wrong? Upvote 0
Thanks. I had seen that. It seems to be suggesting that you close the file but there doesn't seem to be a way to do that in B4r. FS.close doesn't do it and there doesn't appear to be a way to close a file by name. Am I wrong?
C candide Active Member Licensed User Longtime User Nov 2, 2022 #4 yes, it seems we have to close each file before removal. can you try something like that : Code: Copy Dim fs As LittleFS 'in Process_Globals For Each f As File In fs.ListFiles("/") fs.OpenRead(f.Name) fs.close fs.Remove(f.Name) Next Upvote 0
yes, it seems we have to close each file before removal. can you try something like that : Code: Copy Dim fs As LittleFS 'in Process_Globals For Each f As File In fs.ListFiles("/") fs.OpenRead(f.Name) fs.close fs.Remove(f.Name) Next
R RJB Active Member Licensed User Longtime User Nov 4, 2022 #5 No, unfortunately that still gives the error per delete Thanks for the help anyway. Upvote 0
C candide Active Member Licensed User Longtime User Nov 5, 2022 #6 problem is with File.OpenNextFile on esp32, it is blocking the file in open state code below seems working but it is clean to use joinString Code: Copy Dim Lname As String For Each f As File In lfs.ListFiles("/") If Lname.Length <> 0 Then lfs.Remove(Lname) Lname = JoinStrings(Array As String("/",f.name)) Next If Lname.Length <> 0 Then lfs.Remove(Lname) Upvote 0
problem is with File.OpenNextFile on esp32, it is blocking the file in open state code below seems working but it is clean to use joinString Code: Copy Dim Lname As String For Each f As File In lfs.ListFiles("/") If Lname.Length <> 0 Then lfs.Remove(Lname) Lname = JoinStrings(Array As String("/",f.name)) Next If Lname.Length <> 0 Then lfs.Remove(Lname)