1 (изменено: yuriy2000, 2013-07-22 19:53:53)

Тема: VBScript: Извлечь файл из zip-архива средствами Win.Explorer

Коллеги!

Подскажите как, средствами VBScript проверить содержимое zip-архива (получить список файлов),  и извлечь файл без привлечения внешних утилит типа WinRar, 7-zip и прочие...

Прочитал тему здесь, но не понял, к тому же там JScript.

2

Re: VBScript: Извлечь файл из zip-архива средствами Win.Explorer

yuriy2000, формат *.wsf (WSH: пишем сценарии в формате WSF) с лёгкостью позволяет совмещать VBScript и JScript. По поводу общего непонимания ничем помочь не могу. По поводу конкретного — не ранее, чем увижу конкретизацию непонятого.

3 (изменено: yuriy2000, 2013-07-23 18:30:42)

Re: VBScript: Извлечь файл из zip-архива средствами Win.Explorer

Нашел на просторах интернета готовую функцию на VBS для извлечения файлов  из zip-архива

Она, кстати, может быть использована также просто для копирования файлов с выводом "термометра"
(progress bar)

+ открыть спойлер

Sub Extract( ByVal myZipFile, ByVal myTargetDir )
' Function to extract all files from a compressed "folder"
' (ZIP, CAB, etc.) using the Shell Folders' CopyHere method
' (http://msdn2.microsoft.com/en-us/library/ms723207.aspx).
' All files and folders will be extracted from the ZIP file.
' A progress bar will be displayed, and the user will be
' prompted to confirm file overwrites if necessary.
'
' Note:
' This function can also be used to copy "normal" folders,
' if a progress bar and confirmation dialog(s) are required:
' just use a folder path for the "myZipFile" argument.
'
' Arguments:
' myZipFile    [string]  the fully qualified path of the ZIP file
' myTargetDir  [string]  the fully qualified path of the (existing) destination folder
'
' Based on an article by Gerald Gibson Jr.:
' http://www.codeproject.com/csharp/decompresswinshellapics.asp
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com

    Dim intOptions, objShell, objSource, objTarget

    ' Create the required Shell objects
    Set objShell = CreateObject( "Shell.Application" )

    ' Create a reference to the files and folders in the ZIP file
    Set objSource = objShell.NameSpace( myZipFile ).Items( )

    ' Create a reference to the target folder
    Set objTarget = objShell.NameSpace( myTargetDir )

    ' These are the available CopyHere options, according to MSDN
    ' (http://msdn2.microsoft.com/en-us/library/ms723207.aspx).
    ' On my test systems, however, the options were completely ignored.
    '      4: Do not display a progress dialog box.
    '      8: Give the file a new name in a move, copy, or rename
    '         operation if a file with the target name already exists.
    '     16: Click "Yes to All" in any dialog box that is displayed.
    '     64: Preserve undo information, if possible.
    '    128: Perform the operation on files only if a wildcard file
    '         name (*.*) is specified.
    '    256: Display a progress dialog box but do not show the file
    '         names.
    '    512: Do not confirm the creation of a new directory if the
    '         operation requires one to be created.
    '   1024: Do not display a user interface if an error occurs.
    '   4096: Only operate in the local directory.
    '         Don't operate recursively into subdirectories.
    '   8192: Do not copy connected files as a group.
    '         Only copy the specified files.
    intOptions = 256

    ' UnZIP the files
    objTarget.CopyHere objSource, intOptions

    ' Release the objects
    Set objSource = Nothing
    Set objTarget = Nothing
    Set objShell  = Nothing
End Sub 

В общем-то все делается относительно просто через метод .NameSpace объекта Shell.Application, и в то же время  для меня оказалось пара небольших проблем:
1. Метод .CopyHere игнорируют все эти опции типа "Do not display a user interface if an error occur" при извлечении файлов из Zip архива, ну допустим это можно обойти путем извлечением сперва во временный каталог, а потом уже перемещением в нужный каталог...
2. Функция (как и проводник) может работать с  архивом, только если расширение у файла ZIP - вот с этим уже сложней (для меня), можно конечно скопировать файл и поменять расширение, опять же при условии, если  архив небольшой по размеру

Короче я для себя решил - проще использовать внешние утилиты unzip.exe/WinRar через Shell.Run

PS: alexii у меня не получилось заставить работать примеры г-на Rumata, а поскольку я не силен в JavaScript, то мне было проще найти примеры на VBS

4

Re: VBScript: Извлечь файл из zip-архива средствами Win.Explorer

Добрый день

Недавно прикрутил себе скрипт для упаковки файлов в zip архив, все работает классно )
Теперь задачка усложняется, нужно принимать и рапаковывать запароленные zip архивы, почитал форум и таких примеров не нашел, неужели никак не передать пароль в "Shell.Application"?