Prev: Using VBScript to Check for Network Share File?
Next: Help required in fetching data from child nodes
From: "Dave "Crash" Dummy" on 25 Feb 2010 17:16 Now that Windows includes a ZIP utility, is there some way to script it instead of running an external ZIP program (like 7-zip)? -- Crash One man's weed is another man's wildflower.
From: Reventlov on 25 Feb 2010 17:26 Il giorno Thu, 25 Feb 2010 17:16:16 -0500, "Dave \"Crash\" Dummy" <invalid(a)invalid.invalid> ha scritto: >Now that Windows includes a ZIP utility, is there some way to script it >instead of running an external ZIP program (like 7-zip)? '************************************************ ' File: Zip.vbs (VBScript) ' Autore: Giovanni Cenati ' http://digilander.libero.it/Cenati ' CreateEmptyZip (nome dello zip da creare) ' (Crea un nuovo file zip vuoto o sovrascrive quello esistente) ' ' AddFile2Zip (Nome archivio zip, File da aggiungere) ' (Aggiunge un singolo file ad uno zip esistente) ' ' AddFolder2Zip (Nome archivio zip, Cartella da aggiungere all'archivio) ' (Aggiunge ad uno zip esistente il contenuto di una cartella) ' ' 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 'Attende che la copia sia finita set fso=createobject("scripting.filesystemobject") Set h=fso.getFile(ZipFile) do wscript.sleep 300 loop while h.size=< 22 'Ora posso chiudere lo script senza 'interrompere la compressione. wscript.quit 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 '************************************************************** 'UnzipFolder "c:\dati\" 'ZipFile "C:\dati\archivio.zip" 'Set oApp = CreateObject("Shell.Application") 'oApp.Namespace(UnzipFolder).CopyHere oApp.Namespace(ZipFile).Items '************************************************************** -- Giovanni Cenati (Bergamo, Italy) Write to "Reventlov" at katamail com http://digilander.libero.it/Cenati (Esempi e programmi in VbScript) --
From: "Dave "Crash" Dummy" on 26 Feb 2010 10:17 Reventlov wrote: > Il giorno Thu, 25 Feb 2010 17:16:16 -0500, "Dave \"Crash\" Dummy" > <invalid(a)invalid.invalid> ha scritto: > >> Now that Windows includes a ZIP utility, is there some way to >> script it instead of running an external ZIP program (like 7-zip)? > > '************************************************ ' File: Zip.vbs > (VBScript) ' Autore: Giovanni Cenati ' > http://digilander.libero.it/Cenati <snip> Thank you. I don't speak (or read) Italian, so I will miss your valuable notes, but I should be able to figure out the code. -- Crash Life is short. Eat dessert first.
From: mr_unreliable on 26 Feb 2010 14:03 Dave "Crash" Dummy wrote: > I don't speak (or read) Italian, so I will miss your > valuable notes... > hi Crash, You don't need to read Italian, Google will translate it for you: http://translate.google.com/?hl=en# You can give the translator either text or a url. Then pick the input language and the language you want out from the dropdown boxes. What you get out will be a somewhat fractured English, but readable enough. There is plenty of interesting code around on "non-English" websites, and I use google all the time to translate it.. cheers, jw
From: "Dave "Crash" Dummy" on 26 Feb 2010 15:11 mr_unreliable wrote: > Dave "Crash" Dummy wrote: >> I don't speak (or read) Italian, so I will miss your valuable >> notes... > > hi Crash, > > You don't need to read Italian, Google will translate it for you: > > http://translate.google.com/?hl=en# > > You can give the translator either text or a url. Then pick the input > language and the language you want out from the dropdown boxes. > > What you get out will be a somewhat fractured English, but readable > enough. > > There is plenty of interesting code around on "non-English" websites, > and I use google all the time to translate it.. "Fractured" is what is known as an understatement. But I will use the Google translator as a last resort if I have trouble making the code work. -- Crash Life is short. Eat dessert first.
|
Next
|
Last
Pages: 1 2 Prev: Using VBScript to Check for Network Share File? Next: Help required in fetching data from child nodes |