Sub copy
Dim Inp As InputStream
Dim out As OutputStream
Dim externalfilelist As List
Dim Lfolder As ExternalFile
Lfolder=Storage.Root
externalfilelist.Initialize
ListFiles (Lfolder) 'create a list "lstext" of all files in external storage
For Each f As String In File.ListFiles(File.DirInternal & "/temp")
If File.Exists(File.DirInternal & "/temp", f) Then
Inp = File.OpenInput(File.DirInternal & "/temp", f)
Dim test As Int = externFileListTest(f) 'check if the file exists in the list
If test > -1 Then Storage.DeleteFile(externalfilelist.Get(test)) 'if the file exists in the list, delete it.
out= Storage.OpenOutputstream(Storage.CreateNewFile(Lfolder,f))
Wait For (File.Copy2Async(Inp, out)) Complete (Success As Boolean)
File.Delete(File.DirInternal & "/temp", f)
out.close
End If
Next
End Sub
Public Sub ListFiles (Folder As ExternalFile)
Dim files() As Object = Folder.Native.RunMethod("listFiles", Null)
For Each o As Object In files
Dim f As JavaObject = o
externalfilelist.Add(DocumentFileToExternalFile(f))
Next
End Sub
Private Sub DocumentFileToExternalFile (DocumentFile As JavaObject) As ExternalFile
Dim ef As ExternalFile
If DocumentFile.IsInitialized = False Then
Return ef
End If
ef.Initialize
ef.Name = DocumentFile.RunMethod("getName", Null)
' ef.Length = DocumentFile.RunMethod("length", Null)
' ef.IsFolder = DocumentFile.RunMethod("isDirectory", Null)
ef.Native = DocumentFile
' ef.LastModified = DocumentFile.RunMethod("lastModified", Null)
Return ef
End Sub
Sub externFileListTest(text As String) As Int
Dim Test As ExternalFile
For i = 0 To externalfilelist.Size - 1
Test = externalfilelist.Get(i)
If Test.Name = text Then
Return(i)
End If
Next
Return(-1)
End Sub