RoboCopy with email notification
- From: Rob Leenheer
- Date: Mon, 15 Mar 2010 14:48:36 -0700
Hi guys,
Just a hint. If you use RoboCopyPlus (www.robocopyplus.com), it wraps around robocopy to add email notification on warnings and errors to it. You can still use all your existing scripts, with the benifit of having email notification. We're using it here all over the place with great success.
Cheers.
mishra.ra wrote:
Copying Files using RoboCopy
04-Mar-09
I am unable to get the script working . It works when copying to
another folder. I also granted writ epermission on newly creted
folder.
' Script Name: toa_cms.vbs
'
' Description: Move ABM QRM files from one directory to another.
' Email a warning if files have not arrived
'
' Usage: Scheduled on Autosys
'
' Owner: Group Treasury (Ramesh Mishra)
'
' Version Date Changed by Modification
' 1.0 04/12/08 Ramesh Mishra Initial version
' 1.1 18/02/09 Ramesh Mishra Copy files to Transfer folder
'
Option Explicit
Dim busDate, busMonth, robocopypath, objFSO, objFolder, colFiles,
objStartFolder, objFile, objShell, intRunError
Dim sourcefolder, destinationpath, newfolderpath ,copyfileto,
newfolderpath_m
Dim emailaddress, emailsubject, emailtextbody, zipfileprefix,
Today_Date
' Settings
sourcefolder = "\\lonna00001\cdmnt\production\treasury_production
\TOA_CMS"
'sourcefolder = "H:\Scripts\"
destinationpath = "\\lonms05409\Securitisations\Projects\TOA\Extract
Data"
robocopypath = "H:\common\"
emailaddress = "ramesh.mishra@xxxxxxx"
zipfileprefix = "TOA_"
'
----------------------------------------------------------------------------
Dim sFileName: sFileName = "H:\common\RobocopyIncludeFile.vbs"
Dim sConfigFileName: sConfigFileName = "H:\scripts\log
\RobocopyVBConfig.vbs"
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
' Includes a file in the global namespace of the current script
Private Sub IncludeFileAbs (ByVal sFileName)
Const ForReading = 1
Dim f: Set f = fso.OpenTextFile(sFileName, ForReading)
Dim s: s = f.ReadAll()
ExecuteGlobal s
Set f = Nothing
End Sub
' Include library file
IncludeFileAbs sFileName
' Include configuration file
'IncludeFileAbs sConfigFileName
Set fso = Nothing
'
----------------------------------------------------------------------------
' Today's date
Today_Date = Now()
If( Weekday(Today_Date) = 2 ) Then
busDate = DateAdd("d", -3, Today_Date)
Else
busDate = DateAdd("d", -1, Today_Date)
'busd= Now()
End If
' Check if files have arrived
If CountFiles(sourcefolder) < 1 Then
' Send email warning
emailsubject = "WARNING: missing QRM files for " & busDate
emailtextbody = "If this date is a bank holiday then ignore this
warning"
SendEmailMessage emailaddress, emailsubject, emailtextbody
' Exit program
Wscript.Quit
End If
' Format the date folder
newfolderpath_m = destinationpath & _
"\" & _
MonthName(Month(busDate)) & _
" " & _
Year(busDate) & _
" Files"
CreateNewFolder newfolderpath_m
newfolderpath = newfolderpath_m & _
"\" & _
DatePart("yyyy",busDate) & _
Right("0" & DatePart("m",busDate),2) & _
Right("0" & DatePart("d",busDate),2)
CreateNewFolder newfolderpath
Set objShell = CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(newfolderpath_m) Then
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls """ _
& newfolderpath_m & """ /E /C /G everyone:F ", 2, True)
If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for user " _
& strUser & " to home folder " & newfolderpath_m
End If
End If
If fso.FolderExists(newfolderpath) Then
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls """ _
& newfolderpath & """ /E /C /G everyone:F ", 2, True)
If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for user " _
& strUser & " to home folder " & newfolderpath
End If
End If
Set fso = Nothing
Wscript.Echo "Finished: "
Movefiles sourcefolder, newfolderpath
Moe file function:
Sub MoveFiles(sourcefolder, destinationfolder)
Dim objShell: Set objShell = WScript.CreateObject("WScript.Shell")
' Move files
objShell.Run robocopypath & "robocopy.exe " & sourcefolder & " " &
destinationfolder & " /MOV", 0, true
Set objShell = Nothing
End Sub
It doesn't even work with
Previous Posts In This Thread:
On Monday, March 02, 2009 2:05 PM
Pegasus \(MVP\) wrote:
Re: Copying Files using RoboCopy
<mishra.ram@xxxxxxxxx> wrote in message
news:276c6e57-e6b5-4491-8703-4b61d192a5f6@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You need to post detailed error messages. You might also ask yourself why
you use a VB Script to do your job, seeing that you're shelling out to a
console environment to perform the key tasks (cacls.exe, robocopy.exe). Why
not keep it simple and run the whole job as a batch file?
On Monday, March 02, 2009 5:44 PM
Al Dunbar wrote:
Re: Copying Files using RoboCopy
"Pegasus (MVP)" <I.can@xxxxxxxxxx> wrote in message
news:e$JtYn2mJHA.1340@xxxxxxxxxxxxxxxxxxxxxxx
Also, I was puzzled by the OP saying that he could not get the script
working, but that it worked when copying to another folder. I just didn't
have the inclination to read the entire script to try to figure out what it
might be failing to do...
/Al
On Wednesday, March 04, 2009 10:22 PM
mishra.ra wrote:
Copying Files using RoboCopy
I am unable to get the script working . It works when copying to
another folder. I also granted writ epermission on newly creted
folder.
' Script Name: toa_cms.vbs
'
' Description: Move ABM QRM files from one directory to another.
' Email a warning if files have not arrived
'
' Usage: Scheduled on Autosys
'
' Owner: Group Treasury (Ramesh Mishra)
'
' Version Date Changed by Modification
' 1.0 04/12/08 Ramesh Mishra Initial version
' 1.1 18/02/09 Ramesh Mishra Copy files to Transfer folder
'
Option Explicit
Dim busDate, busMonth, robocopypath, objFSO, objFolder, colFiles,
objStartFolder, objFile, objShell, intRunError
Dim sourcefolder, destinationpath, newfolderpath ,copyfileto,
newfolderpath_m
Dim emailaddress, emailsubject, emailtextbody, zipfileprefix,
Today_Date
' Settings
sourcefolder = "\\lonna00001\cdmnt\production\treasury_production
\TOA_CMS"
'sourcefolder = "H:\Scripts\"
destinationpath = "\\lonms05409\Securitisations\Projects\TOA\Extract
Data"
robocopypath = "H:\common\"
emailaddress = "ramesh.mishra@xxxxxxx"
zipfileprefix = "TOA_"
'
----------------------------------------------------------------------------
Dim sFileName: sFileName = "H:\common\RobocopyIncludeFile.vbs"
Dim sConfigFileName: sConfigFileName = "H:\scripts\log
\RobocopyVBConfig.vbs"
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
' Includes a file in the global namespace of the current script
Private Sub IncludeFileAbs (ByVal sFileName)
Const ForReading = 1
Dim f: Set f = fso.OpenTextFile(sFileName, ForReading)
Dim s: s = f.ReadAll()
ExecuteGlobal s
Set f = Nothing
End Sub
' Include library file
IncludeFileAbs sFileName
' Include configuration file
'IncludeFileAbs sConfigFileName
Set fso = Nothing
'
----------------------------------------------------------------------------
' Today's date
Today_Date = Now()
If( Weekday(Today_Date) = 2 ) Then
busDate = DateAdd("d", -3, Today_Date)
Else
busDate = DateAdd("d", -1, Today_Date)
'busd= Now()
End If
' Check if files have arrived
If CountFiles(sourcefolder) < 1 Then
' Send email warning
emailsubject = "WARNING: missing QRM files for " & busDate
emailtextbody = "If this date is a bank holiday then ignore this
warning"
SendEmailMessage emailaddress, emailsubject, emailtextbody
' Exit program
Wscript.Quit
End If
' Format the date folder
newfolderpath_m = destinationpath & _
"\" & _
MonthName(Month(busDate)) & _
" " & _
Year(busDate) & _
" Files"
CreateNewFolder newfolderpath_m
newfolderpath = newfolderpath_m & _
"\" & _
DatePart("yyyy",busDate) & _
Right("0" & DatePart("m",busDate),2) & _
Right("0" & DatePart("d",busDate),2)
CreateNewFolder newfolderpath
Set objShell = CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(newfolderpath_m) Then
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls """ _
& newfolderpath_m & """ /E /C /G everyone:F ", 2, True)
If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for user " _
& strUser & " to home folder " & newfolderpath_m
End If
End If
If fso.FolderExists(newfolderpath) Then
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls """ _
& newfolderpath & """ /E /C /G everyone:F ", 2, True)
If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for user " _
& strUser & " to home folder " & newfolderpath
End If
End If
Set fso = Nothing
Wscript.Echo "Finished: "
Movefiles sourcefolder, newfolderpath
Moe file function:
Sub MoveFiles(sourcefolder, destinationfolder)
Dim objShell: Set objShell = WScript.CreateObject("WScript.Shell")
' Move files
objShell.Run robocopypath & "robocopy.exe " & sourcefolder & " " &
destinationfolder & " /MOV", 0, true
Set objShell = Nothing
End Sub
It doesn't even work with
On Wednesday, March 04, 2009 10:22 PM
hungerford wrote:
Re: Copying Files using RoboCopy
On Mar 2, 4:44=A0pm, "Al Dunbar" <aland...@xxxxxxxxxxx> wrote:
..
folder
-----=AD-
-----=AD-
his
ell")
" &
hy
a
it
The syntax for the robocopy command seems to be incorrect. The syntax
should be ROBOCOPY <source files/folders> <inclusions, exclusions> /
MOVE. In his script, also, there seems to be a lack of spaces
necessary to make the command work correctly. Additionally, this
script should be launched from a %comspec% /K shell. Robocopy is a
command line utility and switches will be ignored if started outside
this shell. I believe that MOVE would be a better switch as it
deletes both the files and the folders as well, if that's what's
intended. I think the code would work with something like this:
objShell.Run "%comspec% /K c:\robocopy.exe " & sourcefolder & " " &
destinationfolder & " /MOVE", 0, true
I hope this is helpful...
Jim
Submitted via EggHeadCafe - Software Developer Portal of Choice
BizTalk Custom Pipeline for Splitting Messages
http://www.eggheadcafe.com/tutorials/aspnet/a0786aaf-c159-40ff-9cf6-241d5e325f42/biztalk-custom-pipeline-f.aspx
.
- Follow-Ups:
- Re: RoboCopy with email notification
- From: Pegasus [MVP]
- Re: RoboCopy with email notification
- Prev by Date: Re: simple .bat help
- Next by Date: Re: RoboCopy with email notification
- Previous by thread: simple .bat help
- Next by thread: Re: RoboCopy with email notification
- Index(es):
Relevant Pages
|