VBScript help please.

Caporegime
Joined
1 Nov 2003
Posts
35,691
Location
Lisbon, Portugal
Hi guys,

I've never been a VBScript guru but a couple of years back I got to a point where I could butcher a script to make it do what I wanted :p - I've since had a long break from any form of scripting.

Anyway, I am making a script for work and I've got it doing 95% of what we need, but just stuck on one bit.

The scripts function is to copy files from multiple directories to others. Variables are set in an external VBS file in case the directories change in the future.

Initially the script prompts to user to confirm they want to run the file copy, then it gets the machine name for the output logfile at the end.

After that it loads an external VBS file which has the variables it needs for source and destination directories.

After that it uses Robocopy to make the file copies.

Finishing with a simple message box confirming everything is finished.

Here is the script.

Code:
'Message Box Prompt

a=MsgBox("This will copy the files",1, "Message Copy")

'Get Computer Name 
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
strComputer = WshNetwork.ComputerName

'Enter path & VBSript name of external file

	Dim gsLibDir : gsLibDir = "C:\Users\jacobe\Documents\Scripts\"
	Dim goFS     : Set goFS = CreateObject( "Scripting.FileSystemObject" )
	ExecuteGlobal goFS.OpenTextFile( gsLibDir & "EFBRS.vbs" ).ReadAll()

'Robocopy Begin process

	Set objshell = CreateObject("WScript.Shell")
		'FOR MANUALS
			'Run Robocopy with logging
				objcommand = "Robocopy.exe " & sLocalDestinationPath & " " & sFinalDestinationPath & " /E /TS /FP /LOG+:C:\log\%COMPUTERNAME%.log"
				objshell.run(objcommand)

		'FOR OPT Files 
			'Run Robocopy with logging
				objcommand = "Robocopy.exe " & sLocalDestinationPath2 & " " & sFinalDestinationPath2 & " /E /TS /FP /LOG+:C:\log\%COMPUTERNAME%.log"
				objshell.run(objcommand)

			'File copy from multiple sources into one destination				
				objcommand = "Robocopy.exe "  & sLocalDestinationPath & " " & sFinalDestinationPath3 & " /E /TS /FP /LOG+:C:\log\%COMPUTERNAME%.log"
				objshell.run(objcommand)
	
				objcommand = "Robocopy.exe "  & sLocalDestinationPath2 & " " & sFinalDestinationPath3 & " /E /TS /FP /LOG+:C:\log\%COMPUTERNAME%.log"
				objshell.run(objcommand)

				
'Copy Complete Message Box
result=MsgBox("Copy Complete",0, "Copy Status")

So this script works. It's been tested. The log file is great, tells you what was skipped/copied/failed etc.

However my boss wants to go one step further and this is where I get stuck. As it will be idio...sorry I mean users running this script. He wants an overall result displayed in the end message box. I've tried googling and cannot find a way to do this.

For example he wants it to show

"Actions finished

- 4 files copied
- 2 skipped
- 0 Failed

*OK*"

The idea being is that if the user gets a message that any of the copy actions have failed it shows them, so they can then proceed to contact us lot to check out the log file.

Is this possible?

Also quick note. I'm a script noob. So go easy on me!
 
Caporegime
OP
Joined
1 Nov 2003
Posts
35,691
Location
Lisbon, Portugal
Shouldnt be too hard mate, where abouts are you getting stuck with the message box showing the actions?

Stelly

Well from googling it seems like a standard "msgbox" has very limited properties/parameters you can mess around with. I am struggling with pulling the results into the message box, finding it difficult to find out where to start! :-/

Suggestions welcome.
 
Caporegime
OP
Joined
1 Nov 2003
Posts
35,691
Location
Lisbon, Portugal
But the thing with the script is that it outputs the results to a log file.

How can I string format the total results of all the file copies?

I understand how once it's captured that info as a string I can build that into the msgbox.

Sorry for the nooby questions.
 
Caporegime
OP
Joined
1 Nov 2003
Posts
35,691
Location
Lisbon, Portugal
Heres a logfile output

Code:
-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------
  Started : 4 de janeiro de 2017 11:11:14
   Source : C:\sourcefolder2\
     Dest : C:\destfolder2\
    Files : *.*
	    
  Options : *.* /TS /FP /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 
------------------------------------------------------------------------------
	                   2	C:\sourcefolder2\
------------------------------------------------------------------------------
               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         2         0         2         0         0         0
   Bytes :       937         0       937         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : 4 de janeiro de 2017 11:11:14
-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------
  Started : 4 de janeiro de 2017 11:11:14
   Source : C:\sourcefolder\
     Dest : C:\destfolder3\
    Files : *.*
	    
  Options : *.* /TS /FP /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 
------------------------------------------------------------------------------
	                   2	C:\sourcefolder\
	  *EXTRA File 		     937 2017/01/03 14:57:39	C:\destfolder3\test source 2.contact
	  *EXTRA File 		       0 2017/01/03 14:51:16	C:\destfolder3\testsource2.txt
	                   0	C:\sourcefolder\1stcopytest\
------------------------------------------------------------------------------
               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         2         0         2         0         0         0
   Files :         2         0         2         0         0         2
   Bytes :       937         0       937         0         0       937
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : 4 de janeiro de 2017 11:11:14
-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------
  Started : 4 de janeiro de 2017 11:11:15
   Source : C:\sourcefolder2\
     Dest : C:\destfolder3\
    Files : *.*
	    
  Options : *.* /TS /FP /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 
------------------------------------------------------------------------------
	                   2	C:\sourcefolder2\
	*EXTRA Dir        -1	C:\destfolder3\1stcopytest\
	  *EXTRA File 		     927 2017/01/03 13:10:48	C:\destfolder3\1stcopytest.contact
	  *EXTRA File 		      10 2016/12/28 14:58:30	C:\destfolder3\testing1.txt
------------------------------------------------------------------------------
               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         1
   Files :         2         0         2         0         0         2
   Bytes :       937         0       937         0         0       937
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : 4 de janeiro de 2017 11:11:15
-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------
  Started : 4 de janeiro de 2017 11:11:15
   Source : C:\sourcefolder\
     Dest : C:\destfolder\
    Files : *.*
	    
  Options : *.* /TS /FP /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 
------------------------------------------------------------------------------
	                   2	C:\sourcefolder\
	                   0	C:\sourcefolder\1stcopytest\
------------------------------------------------------------------------------
               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         2         0         2         0         0         0
   Files :         2         0         2         0         0         0
   Bytes :       937         0       937         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : 4 de janeiro de 2017 11:11:15

Link to download if anyone wants it

http://jacobellwood.co.uk/public/log/LP10PTE5450-04.log
 
Last edited:
Back
Top Bottom