vb.net - Setting A Progress Bar Based On Directory Copy in Visual Basic -


i using visual studio 2010 , coding in visual basic.

i have display progress bar while copying directory. have never worked progress bar before , not sure start. here code have.

if my.computer.filesystem.directoryexists(filepath & "ietms\" & installfile)     frmwait.show()      my.computer.filesystem.copydirectory(strfilename, filepath & "ietms", true)      listview1.items.clear()     testreload()     frmwait.close() else     my.computer.filesystem.createdirectory(filepath & "ietms\" & installfile)      frmwait.show()      my.computer.filesystem.copydirectory(strfilename, filepath & "ietms", true)      listview1.items.clear()     testreload()     frmwait.close()  end if 

i assuming need calculate size of source folder , monitor destination folder size , set progress bar max source folder size , set value of progress bar destination size, not sure how go doing this.

you can count files in source directory , every count files in destination directory. count files in subdirectories can use recursive sub:

private sub countfiles(infolder string, byref result integer)     result += io.directory.getfiles(infolder).count     each f string in io.directory.getdirectories(infolder)         countfiles(f, result)     next end sub 

to use do

dim filecount integer = 0 countfiles("c:\test", filecount) messagebox.show(filecount.tostring) 

set progressbar percentage value pbprogress.value = cint(destcount/sourcecount * 100).

edit: following on question: should use example backgroundworker, or task, or thread, perform copy , update progressbar in timer. example can create sub copying , start sub in new task: private withevents tmrupdatepbg timer private sub startcopy(sourcefolder string, destfolder string) 'copy copy copy copycomplete() end sub private sub copycomplete() tmrupdatepbg.stop() end sub

[...] 'whereever start copy process dim ct new task(sub() startcopy("c:\source", "c:\dest")) ct.start() tmrupdatepbg = new timer tmrupdatepbg.interval = 1000 tmrupdatepbg.start() 

tmrupdatepgb timer. in tick event update progressbar. started when copying process starts , stops when process complete.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -