B4J Question File.Copy with ShowOpenMultiple?

LWGShane

Well-Known Member
Licensed User
Longtime User
I have a FileChooser which is set to ShowOpenMultiple() and returns the files to a list. However, I'm unsure how to handle the list items in the File.Copy or File.Copy2 methods due to each needing a directory.

Thanks,
CBL.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Are you copying all files to the same folder?

You can use this code to get the file name:
B4X:
Sub GetFileName(fullpath As String) As String
   Dim i As Int = fullpath.LastIndexOf("\")
   If i = -1 Then i = fullpath.LastIndexOf("/")
   If i = -1 Then Return fullpath
   If i = fullpath.Length - 1 Then Return ""
   Return fullpath.SubString(i + 1)
End Sub

B4X:
Dim files As List = fc.ShowOpenMultiple(MainForm)
If files.IsInitialized Then
   For Each f As String In files
     File.Copy(f, "", <target>, GetFileName(f))
   Next
End If
 
Upvote 0
Top