?
Solved

progress bar and file copy

Posted on 2005-03-29
3
Medium Priority
?
1,984 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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, 14 hours left to enroll

764 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