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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create folder based on todays date and copy from another folder - log date/time

Status
Not open for further replies.

JC_123

Technical User
Dec 2, 2018
5
GB
I would like the below VBS to write to a text file called backuplog_<date of the vbs ran>) 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_<date of the vbs ran> and inside that lines showing

C: Volume backup Backup <date of the vbs started> 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 <date of the vbs ended> 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()
 
I have managed to resolve the issue by doing it another way. Many thanks to all who read the post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top