B4J Question Deleting Files - Again

rodmcm

Active Member
Licensed User
I create an image and the user can select horizontal slices of the image. He can then store these.
This works fine and I can see the files with the new image sections.
What I cant do is delete them. Enclosed is code

B4X:
' Saves sections of the image
'The user mouse selects the Y value of the image which is stored in Section()

Private Sub btn2SaveAll_Click
    For x = 1 To SectionCounter
        img1= img.Crop(0,Sections(x-1),img.Width,Sections(x)-Sections(x-1))
        Dim Filename As String = "RodPlay" & x & ".jpg"
        out = File.OpenOutput(File.DirApp &"/Drawings/1",Filename , False)        ' creates the file
        img1.WriteToStream(out,100,"JPEG")                                        ' writes image to folder
    Next
End Sub

Private Sub DeleteFiles(FileName As String)
    Dim AllFiles As List
    AllFiles.Initialize
    AllFiles.AddAll(File.ListFiles(FileName))
    'For i=0 To AllFiles.Size-1 Step 1
    For i=0 To AllFiles.Size-1
        Dim x As String=AllFiles.Get(i)
        Log(x)
        Log(File.Delete(FileName,x))
    Next
End Sub

Private Sub btnClear_Click
    Canvas1.ClearRect(0,0,Canvas1.Width,Canvas1.Height)       ' clears the selection lines
    DeleteFiles(File.DirApp &"/Drawings/1")
End Sub

This is the logs
B4JCapture.JPG
 

Daestrum

Expert
Licensed User
Longtime User
Maybe try closing the stream after you write the image. The OS will take it as the file is still in use so won't let it be deleted. (Possibly)
 
Upvote 0

rodmcm

Active Member
Licensed User
Yes that's was a good idea. I set up another folder with files and can delete them
How do I close the stream? There is File.OpenOutput but nothing I can see to close
 
Upvote 0

rodmcm

Active Member
Licensed User
out.close !!!
Had a brain fade.. was looking at the files not the stream
Works like a charm... many thanks
 
Upvote 0
Top