[Q] Best way to copy file at DirDefaultExternal

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello my friend!
I finished my first project that it has 30 driving tests for drive license. But i have a problem.
First i want to inform how app works. When you install and first first first run, programm copies all (505) images of road sighns at DirDefaultExternal. At normal phones with 1Ghz processor there is no problem. I tested yesterday at HTC Wildfire S (600Mhz and 512 RAM) and it took too much time to copy all these files. About 2 secs before copy ends, it throws me a message that my app does not response. If you "wait" and not "forse close" after 2 secs it ends the copy and programm working like a charm. I want to tell you again that my problem occurs only at "low" phones.
Now my question, do you have any better idea how to copy all these 505 images at DirDefaultExternal?? (see my code down)
B4X:
'-----COPY FILES
      If File.Exists(File.DirDefaultExternal,"True.txt")=False Then
         Try
         File.Copy(File.DirAssets,"test.db3",File.DirDefaultExternal,"test.db3")
         For i=1 To 30
         File.MakeDir(File.DirDefaultExternal,"Test" & i)
         Next
         For j=1 To 15
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test1",j & ".jpg")
         Next
         For j=16 To 31
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test2",(j-15) & ".jpg")
         Next
         For j=32 To 46
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test3",(j-31) & ".jpg")
         Next
         For j=47 To 61
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test4",(j-46) & ".jpg")
         Next
         For j=62 To 77
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test5",(j-61) & ".jpg")
         Next
         For j=78 To 92
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test6",(j-77) & ".jpg")
         Next
         For j=93 To 107
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test7",(j-92) & ".jpg")
         Next
         For j=108 To 122
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test8",(j-107) & ".jpg")
         Next
         For j=123 To 137
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test9",(j-122) & ".jpg")
         Next
         For j=138 To 152
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test10",(j-137) & ".jpg")
         Next
         For j=153 To 167
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test11",(j-152) & ".jpg")
         Next
         For j=168 To 183
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test12",(j-167) & ".jpg")
         Next
         For j=184 To 198
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test13",(j-183) & ".jpg")
         Next
         For j=199 To 213
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test14",(j-198) & ".jpg")
         Next
         For j=214 To 229
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test15",(j-213) & ".jpg")
         Next
         For j=230 To 245
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test16",(j-229) & ".jpg")
         Next
         For j=246 To 261
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test17",(j-245) & ".jpg")
         Next
         For j=262 To 277
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test18",(j-261) & ".jpg")
         Next
         For j=278 To 293
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test19",(j-277) & ".jpg")
         Next
         For j=294 To 309
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test20",(j-293) & ".jpg")
         Next
         For j=310 To 325
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test21",(j-309) & ".jpg")
         Next
         For j=326 To 341
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test22",(j-325) & ".jpg")
         Next
         For j=342 To 357
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test23",(j-341) & ".jpg")
         Next
         For j=358 To 373
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test24",(j-357) & ".jpg")
         Next
         For j=374 To 389
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test25",(j-373) & ".jpg")
         Next
         For j=390 To 405
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test26",(j-389) & ".jpg")
         Next
         For j=406 To 421
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test27",(j-405) & ".jpg")
         Next
         For j=422 To 437
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test28",(j-421) & ".jpg")
         Next
         For j=438 To 453
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test29",(j-437) & ".jpg")
         Next
         For j=454 To 469
            File.Copy(File.DirAssets,j & ".jpg",File.DirDefaultExternal & "/Test30",(j-453) & ".jpg")
         Next
         File.WriteString(File.DirDefaultExternal,"True.txt","True")
      Catch
      
      End Try   
      End If
   End If
   '-----COPY FILES
 

stevel05

Expert
Licensed User
Longtime User
Try putting a DoEvents in between each group copy.
 
Upvote 0
Top