×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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()

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

(OP)
I have managed to resolve the issue by doing it another way. Many thanks to all who read the post.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close