Advertisement
omegastripes

create_zip_copy_file_to.vbs

Jan 5th, 2017
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Create zip and copy file to
  2.  
  3. ' MSDN ref
  4. ' Shell object - https://msdn.microsoft.com/ru-ru/library/windows/desktop/bb774094(v=vs.85).aspx
  5. ' IShellDispatch object - https://msdn.microsoft.com/ru-ru/library/windows/desktop/gg537707(v=vs.85).aspx
  6. ' Folder object - https://msdn.microsoft.com/ru-ru/library/windows/desktop/bb787868(v=vs.85).aspx
  7. ' FolderItems object - https://msdn.microsoft.com/ru-ru/library/windows/desktop/bb787800(v=vs.85).aspx
  8. ' FolderItem object - https://msdn.microsoft.com/ru-ru/library/windows/desktop/bb787810(v=vs.85).aspx
  9.  
  10. sDesktop = CreateObject("WScript.Shell").SpecialFolders.Item("Desktop")
  11. sSrc = sDesktop & "\test.txt"
  12. sDest = sDesktop & "\test.zip"
  13. CreateZipCopyFile sSrc, sDest
  14. msgbox "ok"
  15. sDest = sDesktop & "\test1.zip"
  16. CreateZipCopyFile1 sSrc, sDest
  17. msgbox "ok"
  18.  
  19. Sub CreateZipCopyFile(sSrcFile, sDestZipFile)
  20.    
  21.     ' 06 01 2017
  22.     ' create zip and copy file
  23.    
  24.     CreateObject("Scripting.FileSystemObject").OpenTextFile(sDestZipFile, 2, True).Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
  25.     With CreateObject("Shell.Application")
  26.         With .NameSpace(sDestZipFile)
  27.             .CopyHere sSrcFile
  28.             Do
  29.                 WScript.Sleep 10
  30.             Loop Until .Items.Count = 1
  31.         End With
  32.     End With
  33.    
  34. End Sub
  35.  
  36. Sub CreateZipCopyFile1(sSrcFile, sDestZipFile)
  37.    
  38.     ' 06 01 2017
  39.     ' create zip and copy file
  40.    
  41.     Dim sSrcFolder
  42.     Dim sSrcFileName
  43.     Dim oSrcItem
  44.    
  45.     With CreateObject("Scripting.FileSystemObject")
  46.         sSrcFolder = .GetParentFolderName(sSrcFile)
  47.         sSrcFileName = .GetFileName(sSrcFile)
  48.         .OpenTextFile(sDestZipFile, 2, True).Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
  49.     End  With
  50.     With CreateObject("Shell.Application")
  51.         Set oSrcItem = .NameSpace(sSrcFolder).ParseName(sSrcFileName) ' .CopyHere argument as FolderItem object
  52.         With .NameSpace(sDestZipFile)
  53.             .CopyHere oSrcItem
  54.             Do
  55.                 WScript.Sleep 10
  56.             Loop Until .Items.Count = 1
  57.         End With
  58.     End With
  59.    
  60. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement