Guest User

Untitled

a guest
May 26th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. runBackup
  2.  
  3. Function runBackup()
  4. Dim fileName, folderToBackup, fileToBackupTo, currentDate, fileExtensions, eachFileWrite, totalFileWrite
  5.  
  6. currentDate = DAY(date()) & "." & Month(date()) & "." & YEAR(Date())
  7. fileName = "uTorrent " & currentDate & ".zip" 'File name; leave everything from the first "&" onwards
  8. folderToBackup = "C:\Users\mlevit\AppData\Roaming\uTorrent" ' Location you wish to backup
  9. fileExtensions = array("dat", "old") 'Specify which extensions you wish to backup on (i.e. leave as "array()" if you want the entire folder)
  10.  
  11. totalFileWrite = 2500
  12.  
  13. Dim fileSystem, fileObject, getFile
  14.  
  15. set fileSystem = CreateObject("Scripting.FileSystemObject")
  16.  
  17. If Not fileSystem.FolderExists(folderToBackup) Then
  18. gotoError(1000)
  19. End If
  20.  
  21. fileSystem.CreateTextFile(fileName)
  22.  
  23. set fileToBackupTo = fileSystem.GetFile(fileName)
  24.  
  25. If Not fileSystem.FileExists(fileName) Then
  26. gotoError(1001)
  27. End if
  28.  
  29. Dim shellApp, zipFile, folderToZip
  30.  
  31. set shellApp = CreateObject("Shell.Application")
  32. set zipFile = shellApp.NameSpace(fileSystem.GetAbsolutePathName(".") & "\" & fileName)
  33. set folderToZip = shellApp.NameSpace(folderToBackup)
  34.  
  35. 'If file extensions were specified, then run chekc
  36. if (ubound(fileExtensions) > 0) Then
  37. 'Loops through each file in the folder
  38. For Each file In folderToZip.Items
  39. 'Loops through all the file extensions specified above
  40. For Each extension In fileExtensions
  41. 'Looks for a matching file extension within each file name
  42. if (checkFileExtension(fileSystem.GetExtensionName(file), extension)) Then
  43. newZipFileSize = 0
  44.  
  45. zipFile.CopyHere(file)
  46.  
  47. While (newZipFileSize < fileToBackupTo.Size)
  48. newZipFileSize = fileToBackupTo.Size
  49. WScript.Sleep 10000
  50. Wend
  51.  
  52. Exit For
  53. End If
  54. Next
  55. Next
  56. Else
  57. zipFile.CopyHere(folderToZip.Items)
  58. End If
  59.  
  60. WScript.Sleep totalFileWrite
  61.  
  62. MsgBox "Backup has finished." & chr(13) & "A new file was created: " & fileName, 48, "Backup Completed"
  63. WScript.Quit
  64. End Function
  65.  
  66. Function checkFileExtension(fileExtension, extension)
  67. If (StrComp(fileExtension,extension, 1) = 0) Then
  68. checkFileExtension = true
  69. Else
  70. checkFileExtension = false
  71. End If
  72. End Function
  73.  
  74. Function gotoError(errNumber)
  75. Select Case errNumber
  76. Case 1000
  77. MsgBox "The folder you are trying to backup does not exist.", 16, "Missing Folder"
  78. WScript.Quit
  79.  
  80. Case 1001
  81. MsgBox "Could not create the .zip file for backup.", 16, "ZIP FIle"
  82. WScript.Quit
  83. End Select
  84. End Function
Add Comment
Please, Sign In to add comment