0

I'm trying to create a cmd script that recursively traverses a directory and zip each file individually. This I have done here:

for /R %%b IN (*.*) do ( "C:\Program Files\WinRAR\WinRAR.exe" a "%%~nb.zip" "%%b" )

However, I would like to keep the zip files in the original folder structure and have the results be in a separate folder than the original folder. For example:

Before:

/original
    /some_files
        file-1.txt
        file-2.txt

After:

/original
    /some_files
        file-1.txt
        file-2.txt

/packed
    /some_files
        file-1.zip
        file-2.zip

Does anyone have any suggestions on how to alter the original?

0

I was able to figure out something close:

for /R %%b IN (*.*) do ("C:\Program Files\WinRAR\WinRAR.exe" a -ibck "%%~pb\%%~nb.zip" "%%b" )

It creates the zips in the directories they come in. I could add the proper path before %%~pb but it currently pulls the full path "C:\Users\Matt..." so I probably need something different there.

-ibck keeps WinRAR running in the background.

This was good enough to solve my problem though.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.