Click here to Skip to main content
15,889,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI Please, how can i set my progress the progressbar on my form during copying file from one folder to another folder.
Posted
Comments
phil.o 3-Oct-13 10:43am    
Could you post some code about what you did so far, so that we can help the most quick and acurate as possible? Thanks.

1 solution

VB
Dim sr As New IO.FileStream("[copyfrom]", IO.FileMode.Open)
Dim sw As New IO.FileStream("[copyto]", IO.FileMode.Create)
Dim len As Long = sr.Length - 1
Dim buffer(1024) As Byte
Dim bytesread As Integer

While sr.Position < len
    bytesread = (sr.Read(buffer, 0, 1024))
    sw.Write(buffer, 0, bytesread)
    ProgressBar1.Value = CInt(sr.Position / len * 100)
    Application.DoEvents()
End While

sw.Flush()
sw.Close()
sr.Close()
 
Share this answer
 
Comments
syllar 3-Oct-13 13:10pm    
Sorry for late

Thanks for your Solution hansoctantan
i just try it
it work
irfanansari 3-Oct-13 14:53pm    
i try this but there is Always shows
Dim sr As New IO.FileStream("[copyfrom]", IO.FileMode.Open)
Dim sw As New IO.FileStream("[copyto]",
directory not fount i gave it c:\foder name\file name
d:\
Fa3o 14-May-14 21:08pm    
You should try
C:\[floderName]\[filename].[FileType]
D:\[filename].[FileType]

Example :
C:\Windows\Song.mp3
D:\My Music\Song.mp3
GeekyGirlPanacea 11-Sep-15 3:51am    
Thank you for this.
How do i Cancel the copy?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900