noone
Fri Jun 20 16:21:23 CDT 2008
Il giorno Thu, 19 Jun 2008 10:17:01 -0700, =?Utf-8?B?RG91Zw==?=
<Doug@discussions.microsoft.com> ha scritto:
>I also need to compress a folder to a file (.zip) on Windows. One shoul be
>able to do it with winzip (similar to old pkzip, or compress on UNIX) from
>command prompt (need a winzip modual download). A better way would be to use
>net send command to do the same thing with "Send to compressed (zipped)
>Folder" from command prompt. However, I do not know the syntax. If any one
>knows, please share.
' CreateEmptyZip (nome dello zip da creare)
'
' AddFile2Zip (Nome archivio zip, File da aggiungere)
'
' AddFolder2Zip (Nome archivio zip, Cartella da aggiungere all'archivio)
'
' Creates a zip archive and adds one or more files.
' Uses Win XP native support for zip archives as folders.
'************************************************
ScriptFullName = wscript.scriptfullname
CurrentPath = Left(scriptfullname, InStrRev(ScriptFullName, "\"))
ZipFile = CurrentPath & "test.zip"
FileDaAggiungere = wscript.scriptfullname
FolderDaZippare = CurrentPath & "temp\"
'Crea un file zip vuoto.
a = CreateEmptyZip(ZipFile)
msgbox a 'Deve essere True.
'Aggiunge un file all'archivio zip appena creato.
a = AddFile2Zip (ZipFile, FileDaAggiungere)
msgbox a
'Aggiunge il contenuto di un folder all'archivio zip.
a= AddFolder2Zip (ZipFile, FolderDaZippare)
msgbox a
Function AddFile2Zip (sZipFile, sFile2Add)
'Aggiunge un file all'archivio zip esistente.
'Attenzione: di default il metodo CopyFile sovrascrive.
'NameSpace vuole un pathname completo e non solo il nome file.
On Error Resume Next
AddFile2Zip = True
Set oApp = createobject("Shell.Application")
oApp.NameSpace(sZipFile).CopyHere sFile2Add
If Err<>0 Then AddFile2Zip=False
End Function
Function CreateEmptyZip(sPathName)
'Create empty Zip File.
'Crea un file zip vuoto.
Dim fso, fp
Const ForWriting = 2 'Apre un file in scrittura.
CreateEmptyZip = True 'se tutto va bene resta true.
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set fp = fso.OpenTextFile( sPathName, ForWriting, True )
If Err <> 0 Then
Set opfs = Nothing
CreateEmptyZip=False
Exit Function 'Errore nella creazione
end if
fp.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)
If Err <> 0 Then
Set opfs = Nothing
CreateEmptyZip=False
Exit Function 'errore nella scrittura
End If
fp.Close 'Chiude il file, altrimenti non si può usare.
Set fso = Nothing
Err.Clear
End Function
Function AddFolder2Zip (ZipFile, Folder)
'Copia il contenuto di una cartella in un file zip.
'Il folder deve essere indicato con pathname completo
'e terminare con un "\"
'Zipfile deve essere indicato con pathname completo.
AddFolder2Zip=True
Set oApp = CreateObject("Shell.Application")
'Copia il contenuto della cartella nello zip.
Set oFolder = oApp.NameSpace(Folder)
If Not oFolder Is Nothing Then
oApp.NameSpace(ZipFile).CopyHere oFolder.Items
End If
If Err <>0 Then AddFolder2Zip=False
End Function
--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--