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. Title autozip.bat
  3. REM updated 30/07/2015
  4. REM created by: Anonymous
  5. REM modified by: Yashwant Vishwakarma
  6. REM This script compresses files in a folder Note: files with the same name
  7. REM but with different extensions will be in the same archive.
  8. path=%path%;"c:\program files\winrar"
  9. REM ****************** Folder to compress******************
  10. set dir=C:\testzip
  11. REM *******************************************************
  12. REM change to directory
  13. cd %dir%
  14. echo Folder to compress in *.RAR format:
  15. echo %dir%
  16. echo Compressing files started....
  17. REM Compress files in directory individually without subdirectories.
  18. echo.
  19. FOR %%i IN (*.*) do (
  20. rar a "%%~ni" "%%i"
  21. )
  22. 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: