Files
System-Scripts/Microsoft/Windows/CopyGoogleChromeBookmarks.vbs

66 lines
2.1 KiB
Plaintext
Raw Normal View History

2022-10-29 19:37:21 +02:00
' CopyGoogleChromeBookmarks.vbs - Copy Bookmarks File of Google Chrome to HomeDir
' and retain the last 14 Files (by Creation Date)
' v1.0 - 29.10.2022 - Initial Release
' WSHShell
Dim objWSH
Set objWSH = CreateObject("WScript.Shell")
' Define Variables
strProfileFolder = objWSH.ExpandEnvironmentStrings("%LOCALAPPDATA%") & "\Google\Chrome\User Data\Default\"
strBackupBaseFolder = "H:\Backup\"
strBackupFolder = "H:\Backup\Chrome\"
strBackupFile = "BOOKMARKS"
intMaxFiles = 14
' File System Object
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Define actual Backup Folder
strActualBackupFile = strBackupFile & "_" & fncDateTimeString(now())
' Check, whether Backup Base Folder exists
If Not objFSO.FolderExists(strBackupBaseFolder) Then
objFSO.CreateFolder strBackupBaseFolder
End If
' Check, whether Backup Folder exists
If Not objFSO.FolderExists(strBackupFolder) Then
objFSO.CreateFolder strBackupFolder
End If
' Copy File
objFSO.CopyFile strProfileFolder & strBackupFile, strBackupFolder & strActualBackupFile
' Only run if we actually have more than 14 files...
Dim objFolder
Set objFolder = objFSO.GetFolder(strBackupFolder)
If objFolder.Files.Count > intMaxFiles Then
' Create an array to the hold the dates of each file in this folder...
ReDim aryFiles(objFolder.Files.Count - 1)
' Read all Files into an Array
i = 0
For Each oFile In objFolder.Files
aryFiles(i) = oFile.DateCreated
i = i + 1
Next
' Get the 14th most-recent date...
dtmCutOff = aryFiles(i-intMaxFiles)
' Iterate the files once more and delete any files older than our cut-off...
For Each oFile In objFolder.Files
If oFile.DateCreated < dtmCutOff Then oFile.Delete
Next
End If ' objFolder.Files.Count > intMaxFiles
Function fncDateTimeString(datDate)
' Format the Date as yyyymmdd
fncDateTimeString = Year(datDate)& right("0" & Month(datDate),2) & right("0" & Day(datDate),2) & right("0" & Hour(datDate),2) & right("0" & Minute(datDate),2) & right("0" & Second(datDate),2)
End Function