i'm trying write code copy files folder folder progress bar , label
count files, copying 0 files of 10 files
. code not working , throws , error.
collection modified; enumeration operation may not execute.
this code:
imports system.io imports system.net public class form1 dim filestocopy new arraylist() protected overrides sub onload(byval e eventargs) mybase.onload(e) copybtn.text = "copy file" copybtn.parent = me progbar.left = copybtn.right end sub dim withevents copybtn new button dim progbar new progressbar dim withevents filecopier new webclient public sub check(byval sender object, byval e eventargs) handles copybtn.click dim src string = "d:\test" dim dest string = "d:\test2" each dir string in system.io.directory.getfiles(src) dim dirinfo new system.io.directoryinfo(dir) if not system.io.file.exists(dest & "\" & dirinfo.name) filestocopy.add(dirinfo.name) end if next if filestocopy.count > 0 if msgbox("there new files found. want sync now?", msgboxstyle.question + msgboxstyle.yesno, "confirm") = msgboxresult.yes = 0 filestocopy.count - 1 dim filecopier webclient = new webclient addhandler filecopier.downloadprogresschanged, addressof filecopier_downloadprogresschanged addhandler filecopier.downloadfilecompleted, addressof filecopier_downloadfilecompleted copybtn.enabled = false progbar.parent = me filecopier.downloadfileasync(new uri(src & "\" & filestocopy(i)), dest & "\" & filestocopy(i)) next end if else msgbox("no new files copied") end if end sub
this code tracks number of files copying.
private sub filecopier_downloadprogresschanged(byval sender object, byval e downloadprogresschangedeventargs) handles filecopier.downloadprogresschanged progbar.value = e.progresspercentage each file in filestocopy total += filestocopy.add(file) next label2.text = total \ filestocopy.count end sub end class
add here instead in downloadprogresschanged
= 0 filestocopy.count - 1 dim filecopier webclient = new webclient addhandler filecopier.downloadprogresschanged, addressof filecopier_downloadprogresschanged addhandler filecopier.downloadfilecompleted, addressof filecopier_downloadfilecompleted copybtn.enabled = false progbar.parent = me filecopier.downloadfileasync(new uri(src & "\" & filestocopy(i)), dest & "\" & filestocopy(i)) label2.text = + 1 & "/" & filestocopy.count 'put here instead next
Comments
Post a Comment