Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Progress or status bar when copying files

Status
Not open for further replies.

RAR63

Technical User
May 5, 2003
3
0
0
US
I have a simple script that maps to a network drive and then copies the files and directories I want. The copy section is shown below. What I want to do is have a progress bar or status show up on the screen so the user can see the progress of what is being copied and when it is done. Can anybody help me out. Thanks!

'----- Copy files --------

Const ForAppending = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")

Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "C:\My Documents" , "r:\" , OverWriteFiles
objFSO.CopyFolder "C:\Windows\Favorites" , "r:\" , OverWriteFiles
objFSO.CopyFolder "C:\Windows\Application Data\Microsoft" , "r:\" , OverWriteFiles
' objFSO.CopyFolder "C:\Windows\Desktop" , "r:\" , OverWriteFiles
 
Personally, I would just integrate the windows shell.

Set oShell = CreateObject("Shell.Application")
Set oTarget = oShell.Namespace("R:\")
oTarget.CopyHere "C:\My Documents",16


Jon Hawkins
 
Thanks for the replies.

jonscott8 - Does that show a progress bar when the files are being copied?
 
You can use the progress bar const. I use it in my script, it works very well. Here is an example (just populate with your information)
On Error Resume next
Const FOF_CREATEPROGRESSDLG = &H10&
Dim ParentFolder, objShell, objFolder, objNet, strName
Set objNet = CreateObject("Wscript.Network")
strName = objNet.UserName
objNet.MapNetworkDrive "G:", "\\your path\home" & "\" & strName
WScript.Sleep 5000

ParentFolder ="g:\"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(ParentFolder)
objFolder.CopyHere "C:\data", FOF_CREATEPROGRESSDLG
MsgBox ("Backup Completed Succesfully")
 
I think I tried something similar to that CORT1 but for some reason it never showed a dialog box showing the progress. I will copy and paste your code and try it. Thanks!

Does it matter what OS you are running that on? I tried it on Win 98 with WSH 5.1 installed.
 
I tried out the code myself and it took a little trial and error to make me understand which folder was the source and which was the target. I modified it as shown below to help others.

SourceFolder ="P:\UTILS"
TargetFolder = "C:\DATA\"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(TargetFolder)
objFolder.CopyHere SourceFolder, 16
MsgBox ("Backup Completed Succesfully")
 
RE: never showed a dialog. Make sure the transfer takes a few seconds to complete. If you're copying a file/folder that's relatively small, you won't see it. The progress dialog that is displayed is the same as if you manually opened Windows Explorer and performed the transfer.

RE: required OS. You should have no problem with Win 98. Win 2k/98 and later or Win95/NT4 with integrated IE4 or later is required.

Jon Hawkins
 
rar63
The code should work with 98. If you are not getting the progress bar, then I would remove the "on error resume next" command at the top of the window to see were your code is getting caught up. If you run the code with the "on error resume next" and there are errors you will not be able to see them.
The code first maps to a network drive ("as administrator, so make sure you have the proper rights") then sleeps for about 5 seconds and then runs. If you want to do a better test you can map to a local drive on your machine say C:this would map to the root directory. the c:\data folder is were the files are being copied from and they are being copied to the network folder on the G: drive. you will need to change the path from C:\data (unless you create a data folder on your c drive) to wherever you want to copy from. and change the G:\your path to wherever you want to copy to. I hope this helps you, if not I will change the code so that it will definetly work on your machine and send it to you---let me know.
CORT1
 
lewijo,

I am trying to use the code that you supplied, however, I keep getting "Object not defined" on objFolder.CopyHere SourceFolder, 16

Here is my code. Can someone please tell me what I've missed?

On Error Resume Next
Dim objShell
Dim objFolder
Dim SourceFolder
Dim TargetFolder

SourceFolder ="\\atctmf03\PDG\Pragmatech\Templates"
TargetFolder = "c:\RFP\Templates"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(TargetFolder)
objFolder.CopyHere SourceFolder, 16
MsgBox ("Backup Completed Succesfully")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top