Monday, November 24, 2014

How to create a batch file to zip folders from command line



Below given are some easy steps to create a zip file of your files and folders on your computer and copy it to a different drive on your computer.

* Make sure you have either of the file compression software (WinZip / WinRar) installed on your machine.

For Exa: You have 3 folders on your computer's C:\Drive say -

C:\Intel
C:\Logs
C:\Drivers

Now you want to make zip file of "Logs" folder.
You can create a zip file in very short time.

Goto>Start>Run>Notepad

Once the Notepad is open, type the below given contents:-
____________________________________________

@echo ON
rar a backup_Logs.rar "C:\PerfLogs"  
xcopy backup_Logs.rar "D:\"             

_____________________________________________

Save the notepad file with filename = "backup_script.bat" instead of ".txt" file.

What we write in the script:-
(#backup_Logs = Filename of new zip/rar file)
( #xcopy = command to copy zip/rar file to the destination location. In this script its D:\Drive on your computer)

* Now copy zip.exe or rar.exe on C:\Drive where your "backup_script.bat" is saved from the location where WinZip or WinRar is installed.

Once you have saved the file and done with the above steps, simply double click on the file and it will create a zip file of "Logs" folder by itself.

Enjoy.....

No comments:

Post a Comment