Android Question How can I delete photos

dhernandez

Active Member
Licensed User
Longtime User
As I can delete photos stored in external memory in a specified folder?
My application uses photos for evidence, I keep those pictures in the database, but also are stored in the DCIM folder, how can I eliminate them through code?

This is what I tried and it did not.

B4X:
File.Delete(File.DirRootExternal & "/" & "DCIM","DCIM")

Somebody help me with this?

I thank you in advance
 

LucaMs

Expert
Licensed User
Longtime User
B4X:
Dim Path as String
Path = File.Combine(File.DirRootExternal, "DCIM/MyFolder")
File.Delete(Path, "MyFile.jpg")

Obviously, if the files are in the DCIM folder, you do not need to add "/MyFolder".

If you want to delete them all:

B4X:
    Dim Files As List = File.ListFiles(Path)
    Dim FileName As String
    For i = 0 To Files.Size-1
        FileName = Files.Get(i)
        File.Delete(Path, FileName)
    Next
 
Last edited:
Upvote 0

dhernandez

Active Member
Licensed User
Longtime User
Very Thanks...

Lake as I did this and it works :)

B4X:
Dim Lista As List
    Lista.initialize
    Dim MisFotos As String
    Lista = File.ListFiles(File.DirRootExternal & "/DCIM")
    For i = Lista.Size-1 To 0 Step -1
          MisFotos = Lista.Get(i)
          File.Delete(File.DirRootExternal & "/DCIM",MisFotos)
    Next

Thank you for supporting LucaMs... :D

I followed the second example yours :)
 
Upvote 0
Top