Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a source zip file which is located in a user's "My Documents" directory. It is guaranteed to always be there. I'm looking for a way to create a batch or script which will let me unzip that file to a destination directory also within the user's directory. If the destination is already there, it should first delete the existing destination folder.

Example process:

srcFile = %user%\My Documents\file.zip
destFolder = %user%\My Documents\Unzipped\
if destFolder exists, delete it
unzip srcFile to destFolder

I'm looking for a solution that will work on Windows XP and Windows 7. If possible, I don't want to use a zip application other than the one built into Windows XP/7.

share|improve this question
1  
We're not here as a script writing service. ;) So, what have you got so far, and where are you getting stuck? –  techie007 May 28 '13 at 18:50
    
Your last sentence is problematic. Not only does the Compressed Folders function suck, it's not possible to access from the command line AFAIK. You'll probably have to invoke a VBS script from your batch file. If you use a 3rd party command line unzipper what you want to do is really trivial. –  Karan May 28 '13 at 19:10
add comment

1 Answer

up vote 1 down vote accepted

DelUnzip.cmd:

RD /S /Q "%USERPROFILE%\My Documents\Unzipped"
cscript UnzipZip.vbs

UnzipZip.vbs:

strZipFile  = "\file.zip"
strUnzipped = "\Unzipped\"

Sub UnZip(ExtractTo,ZipFile)

Set fso = CreateObject("Scripting.FileSystemObject") 
    If NOT fso.FolderExists(ExtractTo) Then 
       fso.CreateFolder(ExtractTo) 
End If 

Set objShell = CreateObject("Shell.Application") 
Set FilesInZip=objShell.NameSpace(ZipFile).items 

ObjShell.NameSpace(ExtractTo).CopyHere(FilesInZip) 
Set fso = Nothing 
Set objShell = Nothing 
End Sub

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("MyDocuments")

strZipPath   = strDesktop & strZipFile
strUnzipPath = strDesktop & strUnzipped

UnZip strUnzipPath , strZipPath
share|improve this answer
    
I get an error on the last line: "Cannot use parentheses when calling a Sub". Any thoughts on what to fix? –  Michael Mankus May 29 '13 at 11:15
    
@MichaelMankus Sorry, fixed. –  STTR May 29 '13 at 17:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.