forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Windows Zip/Unzip Api question [SOLVED]

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
Tdk161
Valued Contributor
Valued Contributor


Joined: 08 Feb 2005
Posts: 399
Location: ITALY

PostPosted: Mon May 09, 2011 6:37 am    Post subject: Windows Zip/Unzip Api question [SOLVED] Reply with quote

Hi,

It's possible to unzip a zip file using windows Api? and how?

Thank you


Last edited by Tdk161 on Sun May 22, 2011 8:37 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
cnodnarb
Professional Member
Professional Member


Joined: 11 Sep 2002
Posts: 766
Location: Eastman, GA

PostPosted: Mon May 09, 2011 6:47 am    Post subject: Reply with quote

Not directly. This works though.

Code:
rem http://stackoverflow.com/questions/876626/windows-api-to-extract-zip-files
list create,1
list loadtext,1,
"strFile = "C:\Users\Brandon\Downloads\simple_spreadsheet.zip"
"strDest = "C:\Users\Brandon\Downloads\simple_spreadsheet"
"
"Set objFSO = CreateObject("Scripting.FileSystemObject")
"
"If Not objFSO.FolderExists(strDest) Then
"    objFSO.CreateFolder(strDest)
"End If
"
"UnZipFile strFile, strDest
"
"Sub UnZipFile(strArchive, strDest)
"    Set objApp = CreateObject( "Shell.Application" )
"
"    Set objArchive = objApp.NameSpace(strArchive).Items()
"    Set objDest = objApp.NameSpace(strDest)
"
"    objDest.CopyHere objArchive
"End Sub
list savefile,1,@path(%0)temp.vbs
shell open,@path(%0)temp.vbs
Back to top
View user's profile Send private message AIM Address
Tdk161
Valued Contributor
Valued Contributor


Joined: 08 Feb 2005
Posts: 399
Location: ITALY

PostPosted: Mon May 09, 2011 7:00 am    Post subject: Reply with quote

Very Happy Wow cnodnarb,

a very very fast answer

Thank you
Back to top
View user's profile Send private message Send e-mail
cnodnarb
Professional Member
Professional Member


Joined: 11 Sep 2002
Posts: 766
Location: Eastman, GA

PostPosted: Mon May 09, 2011 7:19 am    Post subject: Reply with quote

I use the REM tool from...aw crud! Who made the REM tool? Dang! I'll look it up tomorrow. I'm tired.

Anyway, I REM out the lines with a tool and the do a Find/Replace for loadtext Wink

Works like a charm.
Back to top
View user's profile Send private message AIM Address
cnodnarb
Professional Member
Professional Member


Joined: 11 Sep 2002
Posts: 766
Location: Eastman, GA

PostPosted: Mon May 09, 2011 7:20 am    Post subject: Reply with quote

... by Dr. Dread Idea
Back to top
View user's profile Send private message AIM Address
Tdk161
Valued Contributor
Valued Contributor


Joined: 08 Feb 2005
Posts: 399
Location: ITALY

PostPosted: Mon May 16, 2011 10:52 pm    Post subject: Reply with quote

I've this problem the .vbs created not run but it is open with notepad same with dblclicking Why? Question
Back to top
View user's profile Send private message Send e-mail
Tdk161
Valued Contributor
Valued Contributor


Joined: 08 Feb 2005
Posts: 399
Location: ITALY

PostPosted: Mon May 16, 2011 11:13 pm    Post subject: Reply with quote

now run ( I used cscript <vbsfile>) but return this error:
.vbs(12, 25) Errore di compilazione di Microsoft VBScript: Previsto ')'

this is the script created:
Code:
strFile = "update.zip"
strDest = "c:\passa"

Set objFSO = CreateObject(Scripting.FileSystemObject)

If Not objFSO.FolderExists(strDest) Then
objFSO.CreateFolder(strDest)
End If

UnZipFile strFile

Sub UnZipFile(strArchive
Set objApp = CreateObject( Shell.Application )

Set objArchive = objApp.NameSpace(strArchive).Items()
Set objDest = objApp.NameSpace(strDest)

objDest.CopyHere objArchive
End Sub
[/quote]
Any idea to resolve?
Back to top
View user's profile Send private message Send e-mail
cnodnarb
Professional Member
Professional Member


Joined: 11 Sep 2002
Posts: 766
Location: Eastman, GA

PostPosted: Tue May 17, 2011 12:24 am    Post subject: Reply with quote

Code:
Sub UnZipFile(strArchive 


should be

Code:
Sub UnZipFile(strArchive, strDest)


If will not run in cscript try

Code:

runh wscript my.vbs


instead

cheers Very Happy
Back to top
View user's profile Send private message AIM Address
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1753
Location: Space and Time

PostPosted: Wed May 18, 2011 2:08 pm    Post subject: Reply with quote

Ok. Now how do I ZIP a folder using VBS?
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Tdk161
Valued Contributor
Valued Contributor


Joined: 08 Feb 2005
Posts: 399
Location: ITALY

PostPosted: Wed May 18, 2011 6:23 pm    Post subject: Reply with quote

cnodnarb Smile
thank you very much I
Back to top
View user's profile Send private message Send e-mail
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1753
Location: Space and Time

PostPosted: Wed May 18, 2011 10:48 pm    Post subject: Reply with quote

Found ZIP VBS code.

Code:

Option Explicit

Dim arrResult

arrResult = ZipFolder( "C:\Documents and Settings\MyUserID\Application Data", "C:\MyUserID.zip" )
If arrResult(0) = 0 Then
    If arrResult(1) = 1 Then
        WScript.Echo "Done; 1 empty subfolder was skipped."
    Else
        WScript.Echo "Done; " & arrResult(1) & " empty subfolders were skipped."
    End If
Else
    WScript.Echo "ERROR " & Join( arrResult, vbCrLf )
End If


Function ZipFolder( myFolder, myZipFile )
' This function recursively ZIPs an entire folder into a single ZIP file,
' using only Windows' built-in ("native") objects and methods.
'
' Last Modified:
' October 12, 2008
'
' Arguments:
' myFolder   [string]  the fully qualified path of the folder to be ZIPped
' myZipFile  [string]  the fully qualified path of the target ZIP file
'
' Return Code:
' An array with the error number at index 0, the source at index 1, and
' the description at index 2. If the error number equals 0, all went well
' and at index 1 the number of skipped empty subfolders can be found.
'
' Notes:
' [1] If the specified ZIP file exists, it will be overwritten
'     (NOT APPENDED) without notice!
' [2] Empty subfolders in the specified source folder will be skipped
'     without notice; lower level subfolders WILL be added, wether
'     empty or not.
'
' Based on a VBA script (http://www.rondebruin.nl/windowsxpzip.htm)
' by Ron de Bruin, http://www.rondebruin.nl
'
' (Re)written by Rob van der Woude
' http://www.robvanderwoude.com

    ' Standard housekeeping
    Dim intSkipped, intSrcItems
    Dim objApp, objFolder, objFSO, objItem, objTxt
    Dim strSkipped

    Const ForWriting = 2

    intSkipped = 0

    ' Make sure the path ends with a backslash
    If Right( myFolder, 1 ) <> "\" Then
        myFolder = myFolder & "\"
    End If

    ' Use custom error handling
    On Error Resume Next

    ' Create an empty ZIP file
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )
    Set objTxt = objFSO.OpenTextFile( myZipFile, ForWriting, True )
    objTxt.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
    objTxt.Close
    Set objTxt = Nothing

    ' Abort on errors
    If Err Then
        ZipFolder = Array( Err.Number, Err.Source, Err.Description )
        Err.Clear
        On Error Goto 0
        Exit Function
    End If
   
    ' Create a Shell object
    Set objApp = CreateObject( "Shell.Application" )

    ' Copy the files to the compressed folder
    For Each objItem in objApp.NameSpace( myFolder ).Items
        If objItem.IsFolder Then
            ' Check if the subfolder is empty, and if
            ' so, skip it to prevent an error message
            Set objFolder = objFSO.GetFolder( objItem.Path )
            If objFolder.Files.Count + objFolder.SubFolders.Count = 0 Then
                intSkipped = intSkipped + 1
            Else
                objApp.NameSpace( myZipFile ).CopyHere objItem
            End If
        Else
            objApp.NameSpace( myZipFile ).CopyHere objItem
        End If
    Next

    Set objFolder = Nothing
    Set objFSO    = Nothing

    ' Abort on errors
    If Err Then
        ZipFolder = Array( Err.Number, Err.Source, Err.Description )
        Set objApp = Nothing
        Err.Clear
        On Error Goto 0
        Exit Function
    End If

    ' Keep script waiting until compression is done
    intSrcItems = objApp.NameSpace( myFolder  ).Items.Count
    Do Until objApp.NameSpace( myZipFile ).Items.Count + intSkipped = intSrcItems
        WScript.Sleep 200
    Loop
    Set objApp = Nothing

    ' Abort on errors
    If Err Then
        ZipFolder = Array( Err.Number, Err.Source, Err.Description )
        Err.Clear
        On Error Goto 0
        Exit Function
    End If

    ' Restore default error handling
    On Error Goto 0

    ' Return message if empty subfolders were skipped
    If intSkipped = 0 Then
        strSkipped = ""
    Else
        strSkipped = "skipped empty subfolders"
    End If

    ' Return code 0 (no error occurred)
    ZipFolder = Array( 0, intSkipped, strSkipped )
End Function

_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cnodnarb
Professional Member
Professional Member


Joined: 11 Sep 2002
Posts: 766
Location: Eastman, GA

PostPosted: Wed May 18, 2011 11:51 pm    Post subject: Reply with quote

re: liquidcode

Code:
Const FOF_CREATEPROGRESSDLG = &H0&

Const zipfile = "c:\users\brandon\desktop\zipfile.zip"

Const file1 = "c:\users\brandon\desktop\pos.exe"
Const file2 = "C:\users\brandon\desktop\pos.dsp"
Const file3 = "C:\users\brandon\desktop\pos.dsc"

CreateObject("Scripting.FileSystemObject").CreateTextFile(zipfile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

Set file = CreateObject("Shell.Application")

With file

.NameSpace(zipfile).CopyHere file1, FOF_CREATEPROGRESSDLG

.NameSpace(zipfile).CopyHere file2

.NameSpace(zipfile).CopyHere file3

'count needs to be = to three, if error though check greater as well.

Do Until .NameSpace(zipfile).Items.Count >= 3

wScript.Sleep 1000

Loop

End With


[edit]
Embarassed I see you already found something Wink
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group