0

We have a batch file that uses Windows 10 builtin zip functionality to zip folders. That is so unpredictable and fails in the middle of 1 hr batch job which requires us start the whole process again. The windows builtin zip functionality is not a console app. It brings up user interface elements and fails if someone doesn't click Ok button.

So I started playing with 7z. It is portable app with no dependencies and it is fast. I have a batch file where the current working dir is say c:\work\abuild\job. It has a sub folder maintool\vendorA. I am trying to create a zip file of vendorA folder by passing c:\work\abuild\job\maintool\vendorA as parameter. It is creating the zip with vendorA only content, but retaining the whole c:\work\abuild\job\maintool\vendorA path inside the zip. When extracted, it is ending up creating that folder structure which I don't want.

I looked at all the available command line parameters for 7z. I didn't find one that lets me do this. Instead of using absolute path, if I use a relative path that starts with .\, I can achieve what I want. But that requires total rewrite of this batch file. It is part of bigger batch file solution.

I would be surprised if I am the first one running into this problem. There must be a solution to do this. But I don't know how.

Thanks for your suggestions.

videoguy
  • 161
  • 1
  • 5
  • https://stackoverflow.com/questions/17546016/how-can-you-zip-or-unzip-from-the-script-using-only-windows-built-in-capabiliti – Nordlys Jeger Sep 26 '18 at 17:44
  • Please read my question. Thats where I started and don't want to use builtin zip functionality. I am trying to get this working with 7zip. – videoguy Sep 26 '18 at 17:48
  • 2
    Can you provide the full command your batch file runs? I wasn't able to replicate this with an absolute path. Also, try [this](https://superuser.com/a/340062/911683). Essentially, add an asterisk (`*`) to the end of the path. (`c:\work\abuild\job\maintool\vendorA\*`) – Worthwelle Sep 26 '18 at 18:33
  • Thanks @worthwelle! That is the trick. Once I had \* appended with my absolute path, the generated zip started using relative paths off the absolute dir. – videoguy Sep 28 '18 at 01:01

0 Answers0