woodburyman

ToInfinityAndBeyond

Sep 1st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' This script goes through every subfolder in the specified folder. If the folder has CSV's, it will Zip them and delete the CSV files
  2. ' It gets the Zip file name via the specific path name and alters it slightly
  3. sevzpath = "C:\7z\7z.exe" ' Set the path to the 7zip exe, MUST NOT HAVE SPACES
  4. homedir = "P:\Path\Folder" ' Set starting directory
  5. ' Do not edit bellow here unless you know what you are doing
  6. Set objFSO = CreateObject("Scripting.FileSystemObject")
  7. objStartFolder = homedir
  8. Wscript.Echo "Starting Archive Process in: " & objStartFolder
  9. Set objFolder = objFSO.GetFolder(objStartFolder)
  10. Set colFiles = objFolder.Files
  11. ShowSubfolders objFSO.GetFolder(objStartFolder)
  12. Sub ShowSubFolders(Folder)
  13.     dim ZipsMade
  14.     For Each Subfolder in Folder.SubFolders
  15.         Set objFolder = objFSO.GetFolder(Subfolder.Path)
  16.         Set colFiles = objFolder.Files
  17.         dim x,i
  18.         i = 0
  19.         For each x in objFolder.Files ' Goes throug each file in subfolder
  20.             Dim fso
  21.             Set fso = CreateObject("Scripting.FileSystemObject")
  22.             GetAnExtension = fso.GetExtensionName(x) ' Gets extension of current file
  23.             If GetAnExtension = "csv" Then ' If File is a CSV, adds to a counter
  24.                 i = i + 1
  25.             End If
  26.         Next
  27.         if i>0 Then ' Checks counter, if there is at least 1 CSV file in folder, will go through
  28.             dim pathlength
  29.             pathname1=Subfolder.Path
  30.             pathlength=Len(pathname1) ' Finds How Many Characters current Subfolder has
  31.             pathname2 = Right(pathname1,pathlength-41) ' Removes the first 38 characters from path edit for your own use
  32.             pathname3 = Replace(pathname2,"\",".") ' Replaces \ with .
  33.             Dim oShell
  34.             Set oShell = WScript.CreateObject ("WScript.Shell")
  35.             oShell.Run sevzpath & " -tzip a " & Subfolder.Path & "\" & pathname3 & ".Archive.zip " & Subfolder.Path & "\*.csv", 7, true ' Zips the file with 7z with specified name
  36.             Set oShell = Nothing
  37.             Dim oShell2
  38.             Set oShell2 = CreateObject("Scripting.FileSystemObject")
  39.             oShell2.DeleteFile(Subfolder.Path & "\*.csv") ' Deletes CSV files in folder
  40.             Set oShell2 = Nothing
  41.             ZipsMade = ZipsMade + 1
  42.         end If
  43.         ShowSubFolders Subfolder
  44.     Next
  45. End Sub
  46. Wscript.Echo "Number of Zip Files Made: " & ZipsMade
Add Comment
Please, Sign In to add comment