-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackupFolder.vbs
More file actions
61 lines (48 loc) · 2.16 KB
/
Copy pathBackupFolder.vbs
File metadata and controls
61 lines (48 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Option Explicit
'--------------------------------------------------------------------------------
' ScriptName : BackupFolder.vbs (was copy_folder_aaefolder.vbs)
' Creator : Sungman Han
' Creation Date : 2019-09-16
' Description : Copies a source folder into <destinationRoot>\yyyy_MM_dd.
' Used to snapshot the AAE download folder once a day.
'
' Usage : cscript //nologo BackupFolder.vbs "%USERPROFILE%\Downloads" "D:\backup"
' Output : the folder that was created
' Exit codes : 0 ok | 1 bad arguments | 2 source missing | 3 destination root missing
'
' Changes from the original: no MsgBox (this runs unattended from a scheduled task
' and a modal dialog would block it forever), no hard coded user paths, zero padded
' month and day so the folders sort chronologically, and no doubled backslash.
'--------------------------------------------------------------------------------
Dim vFso, vSource, vRoot, vTarget
If WScript.Arguments.Count < 2 Then
WScript.StdErr.WriteLine "Usage: cscript //nologo BackupFolder.vbs <sourceFolder> <destinationRoot>"
WScript.Quit 1
End If
vSource = WScript.Arguments.Item(0)
vRoot = WScript.Arguments.Item(1)
Set vFso = CreateObject("Scripting.FileSystemObject")
If Not vFso.FolderExists(vSource) Then
WScript.StdErr.WriteLine "Source folder not found: " & vSource
WScript.Quit 2
End If
If Not vFso.FolderExists(vRoot) Then
WScript.StdErr.WriteLine "Destination root not found: " & vRoot
WScript.Quit 3
End If
vTarget = vFso.BuildPath(vRoot, DateStamp())
If Not vFso.FolderExists(vTarget) Then vFso.CreateFolder vTarget
' The trailing separator makes Folder.Copy place the source *inside* vTarget
' instead of trying to become vTarget itself.
vFso.GetFolder(vSource).Copy vTarget & "\", True
Set vFso = Nothing
WScript.StdOut.WriteLine vTarget
WScript.Quit 0
'--------------------------------------------------------------------------------
' Function List
'--------------------------------------------------------------------------------
Function DateStamp()
DateStamp = Year(Date) & "_" & _
Right("0" & Month(Date), 2) & "_" & _
Right("0" & Day(Date), 2)
End Function