Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Create zip and copy file to
- ' MSDN ref
- ' Shell object - https://msdn.microsoft.com/ru-ru/library/windows/desktop/bb774094(v=vs.85).aspx
- ' IShellDispatch object - https://msdn.microsoft.com/ru-ru/library/windows/desktop/gg537707(v=vs.85).aspx
- ' Folder object - https://msdn.microsoft.com/ru-ru/library/windows/desktop/bb787868(v=vs.85).aspx
- ' FolderItems object - https://msdn.microsoft.com/ru-ru/library/windows/desktop/bb787800(v=vs.85).aspx
- ' FolderItem object - https://msdn.microsoft.com/ru-ru/library/windows/desktop/bb787810(v=vs.85).aspx
- sDesktop = CreateObject("WScript.Shell").SpecialFolders.Item("Desktop")
- sSrc = sDesktop & "\test.txt"
- sDest = sDesktop & "\test.zip"
- CreateZipCopyFile sSrc, sDest
- msgbox "ok"
- sDest = sDesktop & "\test1.zip"
- CreateZipCopyFile1 sSrc, sDest
- msgbox "ok"
- Sub CreateZipCopyFile(sSrcFile, sDestZipFile)
- ' 06 01 2017
- ' create zip and copy file
- CreateObject("Scripting.FileSystemObject").OpenTextFile(sDestZipFile, 2, True).Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
- With CreateObject("Shell.Application")
- With .NameSpace(sDestZipFile)
- .CopyHere sSrcFile
- Do
- WScript.Sleep 10
- Loop Until .Items.Count = 1
- End With
- End With
- End Sub
- Sub CreateZipCopyFile1(sSrcFile, sDestZipFile)
- ' 06 01 2017
- ' create zip and copy file
- Dim sSrcFolder
- Dim sSrcFileName
- Dim oSrcItem
- With CreateObject("Scripting.FileSystemObject")
- sSrcFolder = .GetParentFolderName(sSrcFile)
- sSrcFileName = .GetFileName(sSrcFile)
- .OpenTextFile(sDestZipFile, 2, True).Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
- End With
- With CreateObject("Shell.Application")
- Set oSrcItem = .NameSpace(sSrcFolder).ParseName(sSrcFileName) ' .CopyHere argument as FolderItem object
- With .NameSpace(sDestZipFile)
- .CopyHere oSrcItem
- Do
- WScript.Sleep 10
- Loop Until .Items.Count = 1
- End With
- End With
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement