<

Go Premium for a chance to win a PS4. Enter to Win

x

Batch file script to zip individual files from winrar

Published on
6,819 Points
3,119 Views
7 Endorsements
Last Modified:
Introduction:
Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was able to create the below script to complete my task. I have modified the original script as per my requirement & give credit to the creator of this script ( Anonymous ).

For Original script click here...
 
Below is the modified script:
@echo off

Title autozip.bat

REM updated 30/07/2015
REM created by: Anonymous
REM modified by: Yashwant Vishwakarma

REM This script compresses files in a folder Note: files with the same name 
REM but with different extensions will be in the same archive.

path=%path%;"c:\program files\winrar"

REM ****************** Folder to compress******************
set dir=C:\testzip
REM *******************************************************

REM change to directory
cd %dir%

echo Folder to compress in *.RAR format:
echo %dir%

echo Compressing files started....

REM Compress files in directory individually without subdirectories

echo.
FOR %%i IN (*.*) do (
rar a "%%~ni" "%%i"
)
goto eof

Open in new window

For more commands and syntax follow winrar command line help online

In the original batch file script, there were 7 options which required manual intervention to choose and perform tasks. However, I want to completely automate this task so I modified it and its working absolutely fine for me.

Coding Explanation:
Table.pngReferences: 

Conclusion:
This is what I did with a given script, so I wanted to share my learning and experience with you. I hope it will help someone also when this type of requirement will come.

Keep smiling, rising, shining & stay blessed.
                                                                 forefinger-down-512.png****Kindly vote this if you liked this article by clicking on the 'Vote' button & leave your precious comment !!! *****
 
7
Comment
1 Comment
 
LVL 7

Author Comment

by:Yashwant Vishwakarma
Thank You bfuchs :)
Have a great day ahead :)
Keep smiling n shining always :)
Stay blessed :)
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Join & Write a Comment

This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month