Search code examples
windowscmdzip

zip permission denied in batch script


I’m using zip.exe (2.31) on Windows Server 2012R2. I have a large txt file and I want to zip it before transfer it through scp. Thus I will run

zip.exe -1 -m "%DIR%\%~n1.zip" %1 

where %1 is the full path of my txt file. But this script throw out

zip warning: multiple disk information ignored

zip.exe: found a preamble of 20464 bytes

zip warning: name not matched: DIR_PATH\FILE.zip

zip I/O error: Permissions denied

But if I directly type

zip.exe -1 -m DIR_PATH\FILE.zip FILE.txt 

or

zip.exe -1 -m FILE.zip FILE.txt

in the DIR_PATH in cmd (this is exactly same to the line in my script, because I echo it from the script and copy to cmd to run directly), it would work fine.

So why there are errors only when I run this command in script?


Solution

  • This issue might be caused by the compatibility of Windows server 2012R2. After I changed the compatibility setting of the zip.exe to Windows 7, all problems were gone.