stantheman Posted December 2, 2018 Posted December 2, 2018 I would like the below VBS to write to a text file called backuplog_) to a given folder (as a log) the start date/time and the end date/time the process took and show what was copied? Is this possible? In other words, I would like a textfile called backuplog_ and inside that lines showing C: Volume backup Backup Starting at hh:mm:ss Copying Volume_1 folders c:\mydocs\Data\pic1.png c:\mydocs\Data\pic2.jpg etc of each directory and file copied across then at the end of the file and to show the script has finished C: Volume backup Backup Starting at hh:mm:ss I just would like to know how long the process took to backup and a start and end date/time is OK for my needs. Also if it's just possible to show hours and minutes and not seconds that is OK. Here is the code: ----------------------------------------------------------- Option Explicit On Error Resume Next ' Change the following lines Dim sSrcFolder : sSrcFolder = "C:\Data" ' Change Me Dim sDstFolder : sDstFolder = "E:\DataBackup" ' Change Me '======================================= ' Do not change anything after this line Dim DTM : DTM = Now() ' Set date variables Dim Y, M, D, sToday Y = Year(DTM) M = Right("0" & Month(DTM),2) D = Right("0" & Day(DTM),2) sToday = D & "_" & M & "_" & Y ' Set time variables Dim H, N, S, sTime H = Hour(DTM) N = Right("0" & Minute(DTM),2) S = Right("0" & Second(DTM),2) sTime = H & "_" & N & "_" & S ' Create objects Dim oProc Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject") Dim oShell : Set oShell = WScript.CreateObject("WScript.Shell") Sub Main() sDstFolder = sDstFolder & sToday ' Updated the destination folder ' First check if folders exists and create if they dont exist If oFSO.FolderExists(sDstFolder) Then If not oFSO.FolderExists(sTime) Then 'oFSO.CreateFolder(sTime) End If Else ' Create the destination directory if it doesn't exist If Not oFSO.FolderExists(sDstFolder) Then BuildFullPath sDstFolder ' Copy data If oFSO.FolderExists(sSrcFolder) Then oFSO.CopyFolder sSrcFolder & "*", sDstFolder, True If Err.Number <> 0 Then ErrorHandler End If ' Clean up If oFSO.FileExists(sFile) Then oFSO.DeleteFile sFile, True Set oFSO = Nothing Set oShell = Nothing Set oProc = Nothing End Sub Sub BuildFullPath(ByVal FullPath) If Not oFSO.FolderExists(FullPath) Then BuildFullPath oFSO.GetParentFolderName(FullPath) oFSO.CreateFolder FullPath If Err.Number <> 0 Then ErrorHandler End If End Sub Main()
HPlum78 Posted December 2, 2018 Posted December 2, 2018 VBS is that an actual requirement? Could do it in powershell in around 5 lines of code..... 1
stantheman Posted December 2, 2018 Author Posted December 2, 2018 HPlum78 - Not really it can be anything really. I just found the code and thought can it be changed to fit my needs. If it can be 5 lines of code that is even better. Are you able to share on what the lines will be? New to PowerShell but keen to see it work.
stantheman Posted December 16, 2018 Author Posted December 16, 2018 Thanks for the help on this. I have managed to find another way of doing this so but I will look into PowerShell for future tasks.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now