Zip Folder/File through CMD

0 comments

                             Zip Folder/File through CMD


Today you will learn a simple trick and that is how to zip the folder through cmd. Believe me it is useful to you in many ways.
In this tutorial you don't have to do anything. I will provide you one vbs script that you have to save it in your computer and it's all done.





Step 1: 

1. Copy below code and save it as .vbs file.
#------------------------------------------------------------------------------#
set Args = WScript.Arguments
source = Args(0)
' remove trailing slashes as we add slashes when needed later
while Right(source, 1) = "\"
    source = Mid(source, 1, Len(source) - 1)
wend

target = Args(1)

' create empty ZIP file
set fso = CreateObject("Scripting.FileSystemObject")
set zip = fso.OpenTextFile(target, 2, vbtrue)
' write ZIP header, this ensures that Windows recognizes the file as "ZIP Folder"
zip.Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
zip.Close
set zip = nothing
set fso = nothing

' copy files to ZIP file
set app = CreateObject("Shell.Application")

set sourceFolderObj = app.NameSpace(source)
set targetFolderObj = app.NameSpace(target)

for each item in sourceFolderObj.Items
  itemPath = source & "\" & item.Name

  copyItem = false

  ' ZIP file is included in Items collection and is recognized as folder, thus skip it to avoid script errors
  if itemPath <> target then
    if item.IsFolder then
      if item.GetFolder.Items().Count = 0 then
        ' folder is empty, skip it as empty folders can't be compressed
      else
        copyItem = true
      end if
    else
      copyItem = true
    end if
  end if

  if copyItem then
    targetFolderObj.CopyHere sourceFolderObj.Items

    ' wait until the file appears in the ZIP file, 
    ' this is needed because CopyHere() returns immediately after starting an asynchronous copy process 
    ' (starting multiple asynchronous copy will not work as it causes error messages, an invalid ZIP file, ...)
On Error GoTo 0
     DO Until  targetFolderObj.Items.Count = sourceFolderObj.Items.Count
        WScript.Sleep 1000
Loop
  end IF
  
next
set targetFolderObj = nothing
set sourceFolderObj = nothing

set app = nothing

#------------------------------------------------------------------------------#

after saving, it will look like the image given below in windows 8



2.  Last step, open cmd and execute the command given below 

c:\user\zipoo.vbs c:\user\somefolder c:\user\anyname.zip

c:\user\zipoo.vbs      ---- path of the .vbs file
c:\user\somefolder   -----path of the folder you want to zip
c:\user\anyname.zip----- path where you get the zip folder

you can also zip sub-folder or a simple file, just provide the path of the folder/file that you want to zip. 

cmd command image:-


output result:-





                                                         for u .....                                       





Kindly Bookmark this Post using your favorite Bookmarking service:


Post a Comment

Note: only a member of this blog may post a comment.