Use Windows commands to compress files or folders

Source: Internet
Author: User

System Environment:

Requirement: because it is used as a server and does not want to install any third-party software, you have to compress files or folders using the commands that come with windows.

Solution Process:

Usually we use the c: \ Documents ents and Settings \ Root \ sendto \ compression (zipped) folder function to compress, but you can see that this is onlyExplorer Shell Command. For more information, see the original article link.

Because it is not an executableProgramSo we cannot directly call it in cmd, and it seems that the progress cannot be achieved.

Has been installed by default since Windows 98..If you have the idea, start solving it.

Write a vbs script, Zip. vbs

Set objargs = wscript. argumentszipfile = objargs (0) 'create empty ZIP file and open for addingcreateobject ("scripting. fileSystemObject "). createtextfile (zipfile, true ). write "Pk" & CHR (5) & CHR (6) & string (18, vbnullchar) set zip = Createobject ("shell. application "). namespace (zipfile) 'add all files/directories to. zip filefor I = 1 to objargs. count-1 zip. copyhere (objargs (I) wscript. sleep 10000' Required !! (Depending on file/DIR size) Next

Call scripts

Cscript zip. vbs target.zip sourcefile1 sourcedir2

Instance:

Of course, if you are more lazy, you can write a bat processing script to directly write the file to be compressed and double-click it to run it.

Example: Zip. bat

Set src = D: \ src.txt set tar = D: \ tar.zip echo 'in in ZIP files 'cscript D: \ zip. vbs % tar % SRC % echo 'success 'pause

Reference link:

Windows built-in zip instruction http://filext.com/faq/compressed_zip_folder.php

Vbs script http://superuser.com/questions/110991/can-you-zip-a-file-from-the-command-prompt-using-only-windows-built-in-capabili

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.