I have the below backup VB script and it works great!
I would like to modify the Date and Time Stamp so that there is a dash between the Year month date hour and remove the seconds.
How do I modify the below to do this? I am really novice at VB.
'http://www.devhut.net/2013/11/15/vbscript-backup-a-file-and-add-a-date-time-stamp/
'
' This VB file needs to be configured for the source file and the destination folder
' See sSourceFolder, sBackupFolder, sDBFile and sDBFileExt variables and modify as necessary.
'9/17/2015, Iram Alvarez
'This file with make a backup copy with the addition of a Date Time stamp
'Author: Daniel Pineault
Dim objFSO
Dim sSourceFolder
Dim sDestFolder
Dim sDBFile
Dim sDateTimeStamp
Const OVER_WRITE_FILES = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
' sSourceFolder = "C:\Databases\Test" ====>This was the orginal setting
' sBackupFolder = "C:\Users\Daniel\Desktop\New folder (3)" ====>This was the orginal setting
' sDBFile = "Test" ====>This was the orginal setting
' sDBFileExt = "mdb" ====>This was the orginal setting
sSourceFolder = "C:\Users\Iram\Desktop"
sBackupFolder = "C:\Users\Iram\Dropbox\Custom Office Data"
sDBFile = "LLDM_Asistencias_Censo_Estadisticas_Santa Maria"
sDBFileExt = "accdb"
sDateTimeStamp = cStr(Year(now())) & _
Pad(cStr(Month(now())),2) & _
Pad(cStr(Day(now())),2) & _
Pad(cStr(Hour(now())),2) & _
Pad(cStr(Minute(now())),2) & _
Pad(cStr(Second(now())),2)
'If the backup folder doesn't exist, create it.
If Not objFSO.FolderExists(sBackupFolder) Then
objFSO.CreateFolder(sBackupFolder)
End If
'Copy the file as long as the file can be found
If objFSO.FileExists(sSourceFolder & "" & sDBFile & "." & sDBFileExt) Then
objFSO.CopyFile sSourceFolder & "" & sDBFile & "." & sDBFileExt,_
sBackupFolder & "" & sDBFile & "_" & sDateTimeStamp & "." & sDBFileExt,_
OVER_WRITE_FILES
End if
Set objFSO = Nothing
Function Pad(CStr2Pad, ReqStrLen)
'Source: http://saltwetbytes.wordpress.com/2012/10/16/vbscript-adding-datetime-stamp-to-log-file-name/
Dim Num2Pad
Pad = CStr2Pad
If len(CStr2Pad) < ReqStrLen Then
Num2Pad = String((ReqStrlen - Len(CStr2Pad)), "0")
Pad = Num2Pad & CStr2Pad
End If
End Function
Thanks.
Iram