With its current settings it's implied that it is located it Data directory itself.
Code: Select all
#NoEnv
EnvGet, A_UserProfile, UserProfile
; PREFERENCES
; 1) Which folder to backup
; EXAMPLE
; ------------------------------------------
; SourceDir := A_Desktop . "\Test"
; ------------------------------------------
SourceDir := A_ScriptDir
; 2) Which folders and files to exclide from backup
; EXAMPLE
; ------------------------------------------
; ExcludedDirsArray := []
; ExcludedDirsArray.Push(SourceDir . "\Foo")
; ExcludedDirsArray.Push(SourceDir . "\Bar")
; ------------------------------------------
; EXAMPLE
; ------------------------------------------
; ExcludedDirsArray := []
; ExcludedDirsArray.Push() ; If you don't need to exlude anything
; ------------------------------------------
ExcludedDirsArray := []
ExcludedDirsArray.Push()
ExcludedDirs := ""
For Index, Value In ExcludedDirsArray {
ExcludedDirs .= " """ . Value . """"
}
ExcludedDirs := LTrim(ExcludedDirs, " ")
; EXAMPLE
; ------------------------------------------
; ExcludedFilesArray := []
; ExcludedFilesArray.Push(SourceDir . "\Foo.ext")
; ExcludedFilesArray.Push(SourceDir . "\Bar.ext")
; ------------------------------------------
ExcludedFilesArray := []
ExcludedFilesArray.Push()
ExcludedFilesArray.Push()
ExcludedFiles := ""
For Index, Value In ExcludedFilesArray {
ExcludedFiles .= " """ . Value . """"
}
ExcludedFiles := LTrim(ExcludedFiles, " ")
; 3) Where to backup
; EXAMPLE
; ------------------------------------------
; DestinDir := A_Desktop . "\Backup"
; ------------------------------------------
DestinDir := A_ScriptDir . "\_Backup"
; 4) Silent mode
Silent := True
; MAIN PART
If InStr(DestinDir, SourceDir) {
ExcludedDirs .= " """ . DestinDir . """"
}
FormatTime, Timestamp,, yyyy MM dd - HH mm ss
RegExMatch(SourceDir, "^(.*\\)(.*)$", Subpattern)
X := Subpattern2 . " @ " . Timestamp
TempDirX := A_Temp . "\" . X
DestinDirX := DestinDir . "\" . X
If (Silent) {
RunWait, %ComSpec% /c robocopy "%SourceDir%" "%TempDirX%" /e /xd %ExcludedDirs% /xf %ExcludedFiles%,, Hide
}
Else {
RunWait, %ComSpec% /k robocopy "%SourceDir%" "%TempDirX%" /e /xd %ExcludedDirs% /xf %ExcludedFiles%
}
FileMoveDir, % TempDirX, % DestinDirX
If (ErrorLevel) {
FileRemoveDir, % TempDirX, 1
MsgBox, 16,, % "Something went wrong. Backup isn't completed."
}
Else {
MsgBox, 64,, % "Backup is successfully performed:`n" . DestinDir . "\`n" . X
}