-
Notifications
You must be signed in to change notification settings - Fork 1
/
CATBackupSettings.bas
118 lines (90 loc) · 3.26 KB
/
CATBackupSettings.bas
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'MacroName:BackupSettings
'MacroDescription:Backs up Connexion user settings
'Last update: October 4, 2021
Declare Sub MoveFiles(sSrcFolder, sDstFolder)
Declare Sub EraseFolder(sFolder)
Sub Main
Dim sConnexSettingsFolder As String
Dim sBackupLocalFolder As String
Dim sUserDbFolder As String
Dim sUserProfileFolder As String
sConnexSettingsFolder = Environ("APPDATA") & "\OCLC\Connex\"
sBackupLocalFolder = "C:\Users\" & Environ("USERNAME") & "\Documents\ConnexBackup\"
sUserDbFolder = sConnexSettingsFolder & "Db\"
sUserProfileFolder = sConnexSettingsFolder & "Profiles\"
On Error resume Next
MkDir(sBackupLocalFolder)
MkDir(sBackupLocalFolder & "Db")
MkDir(sBackupLocalFolder & "Profiles")
' erase previous backup
Call EraseFolder(sBackupLocalFolder)
Call EraseFolder(sBackupLocalFolder & "Db")
Call EraseFolder(sBackupLocalFolder & "Profiles\")
Call EraseFolder(sBackupLocalFolder & "Profiles\NYPL\")
Call EraseFolder(sBackupLocalFolder & "Profiles\BPL\")
Call EraseFolder(sBackupLocalFolder & "Profiles\MyProfile\")
' delete empty folders
RmDir(sBackupLocalFolder & "Profiles\NYPL\")
RmDir(sBackupLocalFolder & "Profiles\BPL\")
RmDir(sBackupLocalFolder & "Profiles\MyProfile\")
If Dir(sUserProfileFolder & "NYPL\") <> "" Then
MkDir(sBackupLocalFolder & "Profiles\NYPL")
End If
If Dir(sUserProfileFolder & "BPL\") <> "" Then
MkDir(sBackupLocalFolder & "Profiles\BPL")
End If
If Dir(sUserProfileFolder & "MyProfile\") <> "" Then
MkDir(sBackupLocalFolder & "Profiles\MyProfile")
End If
' move general files
Call MoveFiles(sConnexSettingsFolder, sBackupLocalFolder)
' move databases
Call MoveFiles(sUserDbFolder, sBackupLocalFolder & "Db\")
' move default profiles
Call MoveFiles(sUserProfileFolder, sBackupLocalFolder & "Profiles\")
If Dir(sUserProfileFolder & "NYPL\") <> "" Then
Call MoveFiles(sUserProfileFolder & "NYPL\", sBackupLocalFolder & "Profiles\NYPL\")
End If
If Dir(sUserProfileFolder & "BPL\") <> "" Then
Call MoveFiles(sUserProfileFolder & "BPL\", sBackupLocalFolder & "Profiles\BPL\")
End If
If Dir(sUserProfileFolder & "MyProfile\") <> "" Then
Call MoveFiles(sUserProfileFolder & "MyProfile\", sBackupLocalFolder & "Profiles\MyProfile\")
End If
MsgBox "All done! User settings have been backed up to: " & sBackupLocalFolder
End Sub
'#########################################
Sub MoveFiles(sSrcFolder, sDstFolder)
'Copies files from given source directory to given destination directory
Dim nIndex As Integer
Dim i As Integer
Dim DirArr()
Dim sFile As String
sFile = Dir(sSrcFolder)
If Len(sFile) = 0 Then
Goto Done
End If
ReDim DirArr(0)
nIndex = 0
Do While sFile <> ""
ReDim Preserve DirArr(nIndex)
DirArr(nIndex) = sFile
nIndex = nIndex + 1
sFile = Dir
Loop
For i = 0 To nIndex - 1
sFile = DirArr(i)
FileCopy sSrcFolder & sFile, sDstFolder & sFile
Next
Done:
End Sub
'#########################################
Sub EraseFolder(sFolder)
' deletes all files in given directory
Dim sFile
sFile = Dir(sFolder)
Do While sFile <> ""
Kill(sFolder & sFile)
sFile = Dir(sFolder)
Loop
End Sub