Batch File Script to Zip Individual Files from WinRAR

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, examples and websites to complete my task. Finally I was able to create the following script to complete my task. I have modified the original script as per my requirement & obviously credit goes to the creator of this script ( Anonymous ).

For original script, visit here.

The following is the modified script.

  1. @echo off  
  2.   
  3. Title autozip.bat  
  4.   
  5. REM updated 30/07/2015  
  6. REM created by: Anonymous  
  7. REM modified by: Yashwant Vishwakarma  
  8.   
  9. REM This script compresses files in a folder Note: files with the same name   
  10. REM but with different extensions will be in the same archive.  
  11.   
  12. path=%path%;"c:\program files\winrar"  
  13.   
  14. REM ****************** Folder to compress******************  
  15. set dir=C:\testzip  
  16. REM *******************************************************  
  17.   
  18. REM change to directory  
  19. cd %dir%  
  20.   
  21. echo Folder to compress in *.RAR format:  
  22. echo %dir%  
  23.   
  24. echo Compressing files started....  
  25.   
  26. REM Compress files in directory individually without subdirectories.  
  27.   
  28. echo.  
  29. FOR %%i IN (*.*) do (  
  30.    rar a "%%~ni" "%%i"  
  31. )  
  32. goto eof  
For more commands and syntax follow winrar command line help online.

In original batch file script there were 7 options which requires manual intervention to choose and perform task but I want to completely automate this task, therefore modified it and it is working absolutely fine for me.

Coding Explanation:

Command

Conclusion

This is all what I did with a given script and sharing my learning and experience with you. Hope it will help someone if this type of requirement ever comes.

References:

 

Ebook Download
View all
Learn
View all