Android Code Snippet [B4X] CopyFolder / DeleteFolder

Discussion in 'Code Snippets' started by Erel, Aug 8, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User

    A recursive sub that copies a complete folder.

    Private Sub CopyFolder(Source As String, targetFolder As String)
    If File.Exists(targetFolder, "") = False Then File.MakeDir(targetFolder, "")
    For Each f As String In File.ListFiles(Source)
    If File.IsDirectory(Source, f) Then
    File.Combine(Source, f), File.Combine(targetFolder, f))
    End If
    File.Copy(Source, f, targetFolder, f)
    End Sub
    Note that it will not work with the assets folder. You can instead create a zip file and unpack it with the Archiver library.

    Recursively delete a folder and its sub folders:
    Sub DeleteFolder (folder As String)
    For Each f As String In File.ListFiles(folder)
    If File.IsDirectory(folder, f) Then
    File.Combine(folder, f))
    End If
    File.Delete(folder, f)
    End Sub

    Tags: Copy, Folder, Directory
    Last edited: Jan 10, 2019
  2. DonManfred

    DonManfred Expert Licensed User

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice