By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

zip /M fails to delete file after adding to zip file


rem TCC 23.00.25 x64 Windows 10 [Version 10.0.17134.471]

set CurDir=C:\tmp\cwd
if not isdir %[CurDir] md %[CurDir]
set LogDir=C:\tmp\zip
if not isdir %[LogDir] md %[LogDir]

cdd %[CurDir]
del %[LogDir]\test.zip %[LogDir]\*.txt
echo Test1 >%[LogDir]\Test1.txt
echo Test2 >%[LogDir]\Test2.txt

rem zip /M does not delete the file when
rem 1: The zip file already exists
rem 2: the zip file is not in the current working directory
rem Uncomment this cdd to successfully delete Test2.txt after adding it to the zip file
rem cdd %[LogDir]
zip /m %[LogDir]\test.zip %[LogDir]\Test1.txt
zip /m %[LogDir]\test.zip %[LogDir]\Test2.txt

rem Views Test1.txt and Test2.txt in the zip file
zip /v %[LogDir]\test.zip
rem Lists Test2.txt, it is not deleted (although Test1.txt IS deleted)
dir /fa:-d %[LogDir]
The /M option was intended to be used with the /R option (though it also works with /U and /F).

The problem with using a /M with a (default) append operation is that the ZIP file stores the filename without any path info. ZIP /M scans the zip file after the files are successfully added (in a batch operation), and removes the matching local file. Without a /R, no path info is present so ZIP can't delete a file unless it's in the local directory.

/U and /F work because they add each file individually, so after a successful add they know it's OK to delete the source file. But appending files individually for the default add operation would slow ZIP down enormously (as in at least an order of magnitude for multiple files).
A belated thank you for the explanation.

With due respect (and speaking as a computer programmer) the explanation misses the viewpoint of the (this?) user who expects things just to work ...

Slowing "ZIP down enormously" in this instance would have saved me several hours of testing, diagnosis and reporting.

Nevertheless, as always, your product is much appreciated and has been so over many years.

Similar threads