B4R Question Delete all files in folder

Mostez

Well-Known Member
Licensed User
Longtime User
Hello,
I have a folder which has unknown number of files, decreased or increased according to add/delete items. the problem is when I try to loop to remove files I get stack and memory problem, I could not delete more than 40 files of 118. is there a method to remove the whole folder and create it again, or a better way to delete these files?

thanks

B4X:
private Sub DeleteAllUserAccounts () As Boolean
    Private raf As RandomAccessFile
    Dim FileNameArr (16) As Byte
    Dim Fname As String
    raf.Initialize(FileNameArr, True)
    LCD.Clear
    PutString(0,1,"Please Wait...",True)
   
    For Each f As File In SD.ListFiles("dat")
        Dim Fname As String '= JoinStrings (Array As String("dat/",f.name))
        raf.CurrentPosition = 0
        raf.WriteBytes("dat/", 0, 4, raf.CurrentPosition)
        raf.WriteBytes(f.name, 0, 12, raf.CurrentPosition)
        Fname = BC.StringFromBytes(FileNameArr)
       
        Dim del As Boolean    = SD.Remove (Fname)
        If del = False Then Return False
    Next
    LCD.Clear
    Return True

End Sub
 
Top