?
Solved

progress bar and file copy

Posted on 2005-03-29
3
Medium Priority
?
2,012 Views
Last Modified: 2007-12-19
I am new to VB.


how do you create a progress bar?

how do i copy all file and folders of a directory while skipping files that i can't copy for one reason or another?
0
Comment
Question by:Paul S
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 100 total points
ID: 13659507
1) Progress bar
Dim x as integer
ProgressBar1.Min = 0
ProgressBar1.Max = 100
For x = 1 to 100
  ProgressBar1.Value = x
  doEvents
Next x

Alternative:
http://ccrp.mvps.org/index.html?controls/ccrpprogbar6.htm

2) Filecopy

Copy, Move, Delete Files and Folders Using SHFileOperation
http://www.thescarms.com/vbasic/fileops.asp

Alternatives:
How to Copy or Move an Entire Directory using the API
Using the SHFileOperation API, you can easily move or copy entire directories, including all subdirectories.
http://www.mvps.org/vbnet/code/shell/shdirectorycopy.htm


Utilizing Windows SHFileOperation API, Advanced
http://www.mvps.org/vbnet/code/shell/shfileopadv.htm
Build on the SHFileOperation Recycle Bin routine to include multiple file deletions, file moving and file copying, all with the same routine.


How to Copy Files En-mass to a New Folder Using the CopyFile API
http://www.mvps.org/vbnet/code/fileapi/copyfile.htm
Pass a source and target folder and a filespec, and have this routine do the copying. Will create the destination folder if it doesn't exist.
0
 
LVL 14

Assisted Solution

by:Shiju Sasidharan
Shiju Sasidharan earned 100 total points
ID: 13659641
Hi try this
'Goto Project Menu -> Components
' Include Microsoft Windows Common Controls 6.0
' now select a progress bar control and place it on ur form
'
'Goto Project Menu -> References
' include    Microsoft Scripting Runtime
'
'=================================================

Private Sub Form_Load()
    ProgressBar1.Max = 100
    ProgressBar1.Value = 0
End Sub

Private Sub Command5_Click()
    ''Usage
    ' Call CopyAllFiles("C:\Your_Source_Folder", "C:\Your_Dest_Folder")
End Sub

Private Sub CopyAllFiles(SourceFolder, DestFolder As String)

      Dim objFso As New FileSystemObject
      Dim Fld As Folder
      Dim Fls As Files
      Dim Fl As File
      Dim dblPgrBarIncr As Double

      If Not objFso.FolderExists(SourceFolder) Then
          MsgBox SourceFolder & " Doesn't exist", vbExclamation
          Exit Sub
      End If
      If Not objFso.FolderExists(DestFolder) Then
          objFso.CreateFolder DestFolder
      End If
      On Error Resume Next
          Set Fld = objFso.GetFolder(SourceFolder)
          Set Fls = Fld.Files

          dblPgrBarIncr = ProgressBar1.Max / IIf(Fls.Count = 0, 1, Fls.Count)
          For Each Fl In Fls

            If ProgressBar1.Value + dblPgrBarIncr <= ProgressBar1.Max Then
                ProgressBar1.Value = ProgressBar1.Value + dblPgrBarIncr
            Else
                ProgressBar1.Value = ProgressBar1.Max
            End If
            objFso.CopyFile Fl.Path, DestFolder & "\" & Fl.ShortName
            DoEvents
          Next
          ProgressBar1.Value = 0
          Set objFso = Nothing
End Sub

'====================================

;-)
Shiju
0
 
LVL 11

Author Comment

by:Paul S
ID: 13667906
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question