<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; WSH: архивация файлов средствами операционной системы (WinXP)]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=296</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=296&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «WSH: архивация файлов средствами операционной системы (WinXP)».]]></description>
		<lastBuildDate>Tue, 25 Dec 2007 19:47:09 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: WSH: архивация файлов средствами операционной системы (WinXP)]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=7358#p7358</link>
			<description><![CDATA[<p>Пример демонстрирует возможность создать zip-архив с помощью класса. Должен работать как в административном VBScript, так и в ASP:<br /></p><div class="codebox"><pre><code>Set FileSytemObject = CreateObject(&quot;Scripting.FileSystemObject&quot;)
&#039;/// Получаем путь до каталога, в котором находимся
ParentFolderName = FileSytemObject.GetParentFolderName(Wscript.ScriptFullName)
&#039;/// Строим путь для создания тестового файла
SourceFilePath = FileSytemObject.BuildPath(ParentFolderName, &quot;Текстовый документ.txt&quot;)
&#039;/// Создаём и заполняем файл содержимым
FileSytemObject.OpenTextFile(SourceFilePath, 2, True).write &quot;Содержимое файла&quot;
&#039;/// Строим путь для создания архива
DestFilePath = FileSytemObject.BuildPath(ParentFolderName, &quot;1.zip&quot;)
&#039;/// Создаём класс создания ZIP файла
Set Zip = New ZipClass
&#039;/// Создаём новый архив
Zip.CreateArchive DestFilePath
&#039;/// Добавляем файл в архив
Zip.CopyFileToArchive SourceFilePath
&#039;/// Закрываем архив
Zip.CloseArchive

MsgBox &quot;Архив создан&quot;, vbInformation, &quot;ZipClass&quot;

Class ZipClass
    Private Shell
    Private FileSystemObject
    Private ArchiveFolder
    Private ItemsCount

    Private Sub Class_Initialize()
        Set Shell = CreateObject(&quot;Shell.Application&quot;)
        Set FileSystemObject = CreateObject(&quot;Scripting.FileSystemObject&quot;)
    End Sub 

    Function CreateArchive(ZipArchivePath)
        If UCase(FileSystemObject.GetExtensionName(ZipArchivePath)) &lt;&gt; &quot;ZIP&quot; Then
            Exit Function
        End If

        Dim ZipFileHeader
        ZipFileHeader = &quot;PK&quot; &amp; Chr(5) &amp; Chr(6) &amp; String(18, 0)
        FileSystemObject.OpenTextFile(ZipArchivePath, 2, True).Write ZipFileHeader
        Set ArchiveFolder = Shell.NameSpace(ZipArchivePath)
        If Not (ArchiveFolder is Nothing) Then CreateArchive = True
    End Function 

    Function CopyFileToArchive(FilePath)
        If (ArchiveFolder Is Nothing) Then Exit Function
        ArchiveFolder.CopyHere FilePath
        ItemsCount = ItemsCount + 1
    End Function 

    Function CopyFolderToArchive(FolderPath)
        If (ArchiveFolder Is Nothing) Then Exit Function
        ArchiveFolder.CopyHere FolderPath
        ItemsCount = ItemsCount + 1
    End Function 

    Function CloseArchive
        If (ArchiveFolder is Nothing) Then Exit Function
        Set WsriptShell = CreateObject(&quot;Wscript.Shell&quot;)
        If IsObject(Wscript) Then
            Do
                Wscript.Sleep 100
            Loop Until ArchiveFolder.Items.Count =&gt; ItemsCount
        Else
            ServerSleep
        End if
        ItemsCount = 0
    End Function

    Private Function ServerSleep
        Set WsriptShell = CreateObject(&quot;Wscript.Shell&quot;)
        Do
            WsriptShell.Popup &quot;&quot;, 1, &quot;&quot;
        Loop Until ArchiveFolder.Items.Count =&gt; ItemsCount
    End Function

    Function MoveFileToArchive(FilePath)
        If (ArchiveFolder is Nothing) Then Exit Function
        ArchiveFolder.MoveHere FilePath
    End Function
End Class</code></pre></div><p>Автор примера - <strong>Xameleon</strong>.</p>]]></description>
			<author><![CDATA[null@example.com (The gray Cardinal)]]></author>
			<pubDate>Tue, 25 Dec 2007 19:47:09 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=7358#p7358</guid>
		</item>
		<item>
			<title><![CDATA[WSH: архивация файлов средствами операционной системы (WinXP)]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=1738#p1738</link>
			<description><![CDATA[<p>VBS-скрипт, который может сжимать в zip и распаковывать из zip&#039;a:<br /></p><div class="codebox"><pre><code>&#039; ZIP.VBS manipulates ZIP file in command line. 
&#039; Usage: CScript.exe ZIP.VBS [-d|-e|-v] ZIPfile [files...] 
&#039;    CScript.exe ZIP.VBS -a archive.zip 1.txt 

Option Explicit 
Dim arg 
Dim optind 

If WScript.Arguments.Count&lt;1 Then 
 WScript.Echo &quot;Usage: CScript.exe ZIP.VBS [-d|-e|-v] ZIPfile [files...]&quot; 
 WScript.Quit 
End If 
arg=WScript.Arguments(optind) 
Select Case LCase(arg) 
Case &quot;-a&quot;,&quot;-c&quot; 
 optind=optind+1 
 Call MakeZIP() 
Case &quot;-d&quot; 
 optind=optind+1 
 Call DeleteZIP() 
Case &quot;-e&quot; 
 optind=optind+1 
 Call ExtractZIP() 
Case &quot;-v&quot;,&quot;-l&quot; 
 optind=optind+1 
 Call ListZIP() 
Case Else 
 If optind=WScript.Arguments.Count-1 Then 
  Call ListZIP() 
 Else 
  Call MakeZIP() 
 End If 
End Select 
WScript.Quit 

Sub MakeZIP() 
Dim fso 
Dim wShell 
Dim Shell 
Dim n 
Dim ie 
Dim ZIPfile 
Dim ZIPdata:ZIPdata=&quot;PK&quot; &amp; Chr(5) &amp; Chr(6) &amp; String(18,0) 
Dim file 
Dim Folder 
Dim FolderItem 
Dim dFolder 

If WScript.Arguments.Count&lt;optind+2 Then 
 WScript.Echo &quot;Arguments Missing.&quot; 
 WScript.Quit 
End If 

Set fso=CreateObject(&quot;Scripting.FileSystemObject&quot;) 
Set wShell=CreateObject(&quot;WScript.Shell&quot;) 

Set Shell=CreateObject(&quot;Shell.Application&quot;) 
For n=0 To 9 
 For Each ie In Shell.Windows 
  If Not ie.Busy Then 
   If ie.ReadyState=4 Then 
    If InStr(TypeName(ie.Document),&quot;IShellFolderViewDual&quot;)=1 Then 
     Exit For 
    End If 
   End If 
  End If 
 Next 
 If Not IsEmpty(ie) Then Exit For 
 If n=0 Then CreateObject(&quot;WScript.Shell&quot;).Run &quot;explorer.exe&quot;,0,True 
 WScript.Sleep 100 
Next 
If IsEmpty(ie) Then 
 WScript.Echo &quot;Failed&quot; 
 WScript.Quit 
End If 
Set Shell=ie.Document.Application 

ZIPfile=fso.GetAbsolutePathName(WScript.Arguments(optind)) 
If UCase(fso.GetExtensionName(ZIPfile))&lt;&gt;&quot;ZIP&quot; Then 
 WScript.Echo &quot;Invalid Extension Name -&quot;,fso.GetExtensionName(ZIPfile) 
 WScript.Quit 
End If 
If Not fso.FileExists(ZIPfile) Then 
 fso.CreateTextFile(ZIPfile,False).Write ZIPdata 
End If 
Set dFolder=Shell.NameSpace(ZIPfile) 
For optind=optind+1 To WScript.Arguments.Count-1 
 file=fso.GetAbsolutePathName(WScript.Arguments(optind)) 
 Set Folder=Shell.NameSpace(fso.GetParentFolderName(file)) 
 Set FolderItem=Folder.ParseName(fso.GetFileName(file)) 
 If FolderItem Is Nothing Then 
  WScript.Echo WScript.Arguments(optind),&quot;- Not Found.&quot; 
  WScript.Quit 
 End If 
 dFolder.CopyHere FolderItem 
Next 
End Sub 

Sub ListZIP() 
Dim fso 
Dim Shell 
Dim ZIPfile 
Dim Folder 
Dim FolderItem 
Dim k 
Dim COL:COL=8 
Dim cols 
ReDim cols(COL) 
Dim rows 
Dim j 

If WScript.Arguments.Count&lt;optind+1 Then 
 WScript.Echo &quot;Arguments Missing.&quot; 
 WScript.Quit 
End If 

Set fso=CreateObject(&quot;Scripting.FileSystemObject&quot;) 
Set Shell=CreateObject(&quot;Shell.Application&quot;) 
ZIPfile=fso.GetAbsolutePathName(WScript.Arguments(optind)) 
If UCase(fso.GetExtensionName(ZIPfile))&lt;&gt;&quot;ZIP&quot; Then 
 WScript.Echo &quot;Invalid Extension Name -&quot;,fso.GetExtensionName(ZIPfile) 
 WScript.Quit 
End If 
Set Folder=Shell.NameSpace(ZIPfile) 
ReDim rows(Folder.Items.Count) 
For k=0 To COL 
 cols(k)=Folder.GetDetailsOf(,k) 
Next 
j=0 
rows(j)=Join(cols,vbTab) 
For Each FolderItem In Folder.Items 
 For k=0 To COL 
  Cols(k)=Folder.GetDetailsOf(FolderItem,k) 
 Next 
 j=j+1 
 rows(j)=Join(cols,vbTab) 
Next 
WScript.Echo Join(rows,vbCRLF) 
End Sub 

Sub DeleteZIP() 
Dim fso 
Dim Shell 
Dim ZIPfile 
Dim Folder 
Dim FolderItem 

If WScript.Arguments.Count&lt;optind+2 Then 
 WScript.Echo &quot;Arguments Missing.&quot; 
 WScript.Quit 
End If 

Set fso=CreateObject(&quot;Scripting.FileSystemObject&quot;) 
Set Shell=CreateObject(&quot;Shell.Application&quot;) 
ZIPfile=fso.GetAbsolutePathName(WScript.Arguments(optind)) 
If UCase(fso.GetExtensionName(ZIPfile))&lt;&gt;&quot;ZIP&quot; Then 
 WScript.Echo &quot;Invalid Extension Name -&quot;,fso.GetExtensionName(ZIPfile) 
 WScript.Quit 
End If 
Set Folder=Shell.NameSpace(ZIPfile) 
For optind=optind+1 To WScript.Arguments.Count-1 
 Set FolderItem=Folder.ParseName(WScript.Arguments(optind)) 
 If FolderItem Is Nothing Then 
  WScript.Echo WScript.Arguments(optind),&quot;- Not Found.&quot; 
  WScript.Quit 
 End If 
&#039; FolderItem.InvokeVerb(&quot;delete&quot;) 
 FolderItem.InvokeVerb(&quot;??(&amp;D)&quot;) 
Next 
End Sub 

Sub ExtractZIP() 
Dim fso 
Dim Shell 
Dim ZIPfile 
Dim Folder 
Dim FolderItem 
Dim dFolder 

If WScript.Arguments.Count&lt;optind+1 Then 
 WScript.Echo &quot;Arguments Missing.&quot; 
 WScript.Quit 
End If 

Set fso=CreateObject(&quot;Scripting.FileSystemObject&quot;) 
Set Shell=CreateObject(&quot;Shell.Application&quot;) 
ZIPfile=fso.GetAbsolutePathName(WScript.Arguments(optind)) 
If UCase(fso.GetExtensionName(ZIPfile))&lt;&gt;&quot;ZIP&quot; Then 
 WScript.Echo &quot;Invalid Extension Name -&quot;,fso.GetExtensionName(ZIPfile) 
 WScript.Quit 
End If 
Set Folder=Shell.NameSpace(ZIPfile) 
Set dFolder=Shell.NameSpace(fso.GetAbsolutePathName(&quot;&quot;)) 
If WScript.Arguments.Count&lt;optind+2 Then 
 dFolder.CopyHere Folder.Items 
Else 
 For optind=optind+1 To WScript.Arguments.Count-1 
  Set FolderItem=Folder.ParseName(WScript.Arguments(optind)) 
  If FolderItem Is Nothing Then 
   WScript.Echo WScript.Arguments(optind),&quot;- Not Found.&quot; 
   WScript.Quit 
  End If 
  dFolder.CopyHere FolderItem 
 Next 
End If 
End Sub</code></pre></div><p>Скрипт опубликовал <strong>YMP</strong>, взято с форума <a href="http://www.autohotkey.com/forum/topic15135-15.html">AutoHotkey</a>.<br />Кроме того, в WinXP можно использовать консольные утилиты <strong>makecab</strong> и <strong>expand</strong> для сжатия в cab и распаковки из cab&#039;a.</p>]]></description>
			<author><![CDATA[null@example.com (The gray Cardinal)]]></author>
			<pubDate>Fri, 26 Jan 2007 11:43:18 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=1738#p1738</guid>
		</item>
	</channel>
</rss>
