Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Foldercopyprogress shown in progressbar

Foldercopyprogress shown in progressbar

Scheduled Pinned Locked Moved Visual Basic
help
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wassilli
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • W Wassilli

      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

      S Offline
      S Offline
      skrtbh
      wrote on last edited by
      #2

      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 :)

      W 1 Reply Last reply
      0
      • S skrtbh

        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 :)

        W Offline
        W Offline
        Wassilli
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • W Wassilli

          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

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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 call File.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

          W 1 Reply Last reply
          0
          • D Dave Kreskowiak

            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 call File.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

            W Offline
            W Offline
            Wassilli
            wrote on last edited by
            #5

            Thanks for your reply :) I will try to write a code using your suggestions. I hope I can do it. I'im still a beginner in VB.Net. :doh:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups