Foldercopyprogress shown in progressbar
-
Hello I'am trying to copy a folder to another drive. I'am doing this with the FileSystemObject fso. Now, I want that the progress of the copying is shown in a Progressbar. All that I get is that first the folder is copied and then the progressbar is shown. I'd like to have it at the same time. Please excuse my English. I'm not used to speak it very often, but I can understand most of it. Any help would be greatly appreciated. :confused: Here is the code for copying the folder:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim md As String Dim di As String md = "C:\Eigene Dateien" di = "Laufwerk \i:" timer1.enabled = true Label1.Text = "Achtung: Datentranfer läuft. Bitte warten." Label1.Refresh() Dateien_Kopieren() Label1.Text = "Kopiervorgang ist abgeschlossen" MessageBox.Show("Der Ordner " & md & " ist nach " & di & " kopiert.") End Sub Private Sub Dateien_Kopieren() Dim fso As FileSystemObject fso = CreateObject("Scripting.FileSystemObject") fso.DeleteFolder("i:\Eigene Dateien", True) fso.CopyFolder("C:\Dokumente und Einstellungen\Christoph Schmid\Eigene Dateien", "i:\") End Sub
Other controls on the form are a progressbar and a timer.Private Sub Timer1_Tick() progressbar1.value = progressbar1.value + 1 End Sub
-
Hello I'am trying to copy a folder to another drive. I'am doing this with the FileSystemObject fso. Now, I want that the progress of the copying is shown in a Progressbar. All that I get is that first the folder is copied and then the progressbar is shown. I'd like to have it at the same time. Please excuse my English. I'm not used to speak it very often, but I can understand most of it. Any help would be greatly appreciated. :confused: Here is the code for copying the folder:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim md As String Dim di As String md = "C:\Eigene Dateien" di = "Laufwerk \i:" timer1.enabled = true Label1.Text = "Achtung: Datentranfer läuft. Bitte warten." Label1.Refresh() Dateien_Kopieren() Label1.Text = "Kopiervorgang ist abgeschlossen" MessageBox.Show("Der Ordner " & md & " ist nach " & di & " kopiert.") End Sub Private Sub Dateien_Kopieren() Dim fso As FileSystemObject fso = CreateObject("Scripting.FileSystemObject") fso.DeleteFolder("i:\Eigene Dateien", True) fso.CopyFolder("C:\Dokumente und Einstellungen\Christoph Schmid\Eigene Dateien", "i:\") End Sub
Other controls on the form are a progressbar and a timer.Private Sub Timer1_Tick() progressbar1.value = progressbar1.value + 1 End Sub
-
Found this via Google: http://www.vbcity.com/forums/topic.asp?tid=23857[^] I'm sorry I don't have VS6 installed atm, so I wasn't able to check that sample out - hope it'll be useful though :)
Thanks for the link:) I'm sorry, I didn't say that I want to do the code with VB.Net. I don't have VS6 installed any more, but I have transformed the code from the link into VB.Net-code but I have several problems debugging it. I have seen many useful examples with a Progressbar in this forum, but I didn't find what I was looking for. Thanks
-
Thanks for the link:) I'm sorry, I didn't say that I want to do the code with VB.Net. I don't have VS6 installed any more, but I have transformed the code from the link into VB.Net-code but I have several problems debugging it. I have seen many useful examples with a Progressbar in this forum, but I didn't find what I was looking for. Thanks
In order for a Progress Bar to work, you need two things. You need to know how much work your doing (total number of files or total size of all files) and a mechanism to report how far you've gotten through that work. Using the FileSystemObject
.CopyFolder
method won't give you either of those. In order to get the total amount of work to be done, you'll need to either count the number of files in the source directory (and all subdirectories) or the number of bytes in those files. Either way, the data collection method is the same. Use a recursive function, that takes a full fileystem path as a parameter and returns the total number of files/bytes in that folder and all subfolders, to enumerate all the files in a folder, then call itself with the path to each one of the subdirectories, one at a time. Now, copying the files follows the same rescursive method, but it updates the Progress Bar with how many files/bytes have been copied. If you're counting files, then all you need to do is callFile.Copy
with the full path to the source and destination filenames. Update the Progress Bar after each file copy is completed. If you're counting bytes, that gets a little more complicated. But just write your own Copy function that takes the same file path parameters for source and destination. This function will then have to open the source file (Binary mode preferrably), read a block of bytes and copy them to the destination file. Update the Progress Bar with the number of bytes that have been copied. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome -
In order for a Progress Bar to work, you need two things. You need to know how much work your doing (total number of files or total size of all files) and a mechanism to report how far you've gotten through that work. Using the FileSystemObject
.CopyFolder
method won't give you either of those. In order to get the total amount of work to be done, you'll need to either count the number of files in the source directory (and all subdirectories) or the number of bytes in those files. Either way, the data collection method is the same. Use a recursive function, that takes a full fileystem path as a parameter and returns the total number of files/bytes in that folder and all subfolders, to enumerate all the files in a folder, then call itself with the path to each one of the subdirectories, one at a time. Now, copying the files follows the same rescursive method, but it updates the Progress Bar with how many files/bytes have been copied. If you're counting files, then all you need to do is callFile.Copy
with the full path to the source and destination filenames. Update the Progress Bar after each file copy is completed. If you're counting bytes, that gets a little more complicated. But just write your own Copy function that takes the same file path parameters for source and destination. This function will then have to open the source file (Binary mode preferrably), read a block of bytes and copy them to the destination file. Update the Progress Bar with the number of bytes that have been copied. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome