Android Question Copy/move files with progress indication

Status
Not open for further replies.

EvgenyB4A

Active Member
Licensed User
Longtime User
I need to copy or move the number of text files from one folder to another. The target is USB drive.
How to show the progress of copying/moving files and then indicate to remove the flash drive when all the files are copied/moved?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Add all the files names to a global list.
2. Create a sub that copies a file, updates the progress bar and calls itself with CallSubDelayed.
B4X:
Sub CopyFile
 If AllFiles.Size = 0 Then
  Complete
 Else
  Dim f As String = AllFiles.Get(0)
  AllFiles.RemoveAt(0)
  File.Copy(...)
  ProgressBar.Progress = Max(0, 100 - AllFiles.Size)
  CallSubDelayed(Me, "CopyFile")
End Sub

Sub Complete
 Log("Complete")
End Sub
 
Upvote 0

EvgenyB4A

Active Member
Licensed User
Longtime User
1. Add all the files names to a global list.
2. Create a sub that copies a file, updates the progress bar and calls itself with CallSubDelayed.
B4X:
Sub CopyFile
If AllFiles.Size = 0 Then
  Complete
Else
  Dim f As String = AllFiles.Get(0)
  AllFiles.RemoveAt(0)
  File.Copy(...)
  ProgressBar.Progress = Max(0, 100 - AllFiles.Size)
  CallSubDelayed(Me, "CopyFile")
End Sub

Sub Complete
Log("Complete")
End Sub
Thank you very much. I will try.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
1. Add all the files names to a global list.
2. Create a sub that copies a file, updates the progress bar and calls itself with CallSubDelayed.
B4X:
Sub CopyFile
 If AllFiles.Size = 0 Then
  Complete
 Else
  Dim f As String = AllFiles.Get(0)
  AllFiles.RemoveAt(0)
  File.Copy(...)
  ProgressBar.Progress = Max(0, 100 - AllFiles.Size)
  CallSubDelayed(Me, "CopyFile")
End Sub

Sub Complete
 Log("Complete")
End Sub

Sorry to wake this old thread @Erel but I am curious why you didn't suggest a For Next loop that copies all the files instead of calling the function from itself. I am performing a batch move of files and some users are complaining that the process gets stuck with the UI not responding, even though I am using File.Copy2Async. Does it have something to do with the fact that I am copying all files in a For Next loop, unlike your above suggestion?
 
Upvote 0
Status
Not open for further replies.
Top