How to create a batch script that can be used in any folder, to zip its contents?

Discussion in 'other software & services' started by paulescobar, Dec 28, 2011.

Thread Status:
Not open for further replies.
  1. paulescobar

    paulescobar Registered Member

    Joined:
    Sep 22, 2008
    Posts:
    181
    I'd like to create a batch file (extension ".bat") which will:
    - when executed from a certain folder, will archive all the files in that certain folder

    I'm currently using Windows XP, with both WinRar & 7zip installed. So a batch script using either of those archiving softwares would be fine.

    When I searched online, the available tutorials only covered the archiving of specific folders. Whereas I'd like to create a single "portable" batch file...wherever I'd place it, it would zip the files in that specific folder.

    Thanks for any help!
     
    Last edited: Dec 28, 2011
  2. majoMo

    majoMo Registered Member

    Joined:
    Aug 31, 2007
    Posts:
    938
    Hi paulescobar, try this:
     
  3. paulescobar

    paulescobar Registered Member

    Joined:
    Sep 22, 2008
    Posts:
    181
    Thanks for your suggestion majoMo!

    Going off of the suggestions, I tweaked it a little bit to include zip format, compression, & adopting name of current folder....this is what it ends up being:
    Code:
    set zdir="C:\Program Files\7-Zip"
    for %%A in ("%~dp0.") do echo %%~nA>tmp.txt
    set /p fname=< tmp.txt
    del tmp.txt
    %zdir%\7z.exe a -tzip -mx=9 "%fname%".zip *.* -r -x!"portable zip.bat"
    Where "portable zip.bat" is the name of our bat file...modified according to your bat's name.

    And, yeah, this ends up being totally portable & able to zip contents of any folder its executed from.
     
Loading...
Thread Status:
Not open for further replies.