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

Jul 31, 2010

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]\ %[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]\ %[LogDir]\Test1.txt
zip /m %[LogDir]\ %[LogDir]\Test2.txt

rem Views Test1.txt and Test2.txt in the zip file
zip /v %[LogDir]\
rem Lists Test2.txt, it is not deleted (although Test1.txt IS deleted)
dir /fa:-d %[LogDir]


Staff member
May 14, 2008
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).
Jul 31, 2010
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
Thread starter Title Forum Replies Date
R Fixed Internal ZIP command fails to process multiple files Support 3
C Documentation Help nix ZIP /M Support 0
Chen Touboul Failed to ZIP Support 9
Joe Caverly 7zip command links to zip help Support 0
T How to? ZIP/7ZIP @listfile with folders Support 2
Joe Caverly UNZIPping older .ZIP files Support 3
M Is the file corrupted? Support 8
C ZIP/U compares wrong timestamp Support 13
C ZIP Support 0
vefatica ZIP? Support 13
D Zip errors on large files. Support 4
C ZIP .vs. PkZip Support 21
mikea Questions re: Internal ZIP command Support 5
S How to? Set the timestamp of ZIP command built archive to match latest member Support 8
C ZIP behavior Support 5
Frank ZIP: howto store directory in the zip-file Support 20
vefatica ZIP /U a little screwy Support 9
J zip wrong central directory signature Support 12
C Vince - your FTP'ed's Support 1
ehab aboudaya WAD starting tcmd.exe with dir that has Boost C++ Libraries zip file delays Support 2
T Paths in ZIP Support 1
fpefpe zip command file size Support 1
T Zip and reparse points Support 7
J ZIP Help - minor quibble Support 0
H V12 Zip encryption Support 1
S ZIP support in next version? Support 1
vefatica ZIP's informative output Support 1
D Zip /q Support 0
H ZIP/UNZIP issues Support 4
S Version 11 ZIP /V - Permission denied on Network drive Support 2
Joe Caverly ZIP, UNZIP v11 Beta Support 6
samintz COPY fails to copy from \\wsl$ Support 20
M Goto fails when a text endtext block precedes the code Support 5
vefatica SETP usually fails with a 32 bit process Support 4
S INPUT fails if the entered text contains pair of square brackets Support 6
B Request Manual Key fails Support 3
L TCC V22 installer fails signature validation Support 0
A Fixed v25 regression: Parameter expansion fails in piped commands Support 2
vefatica START /PGM "name with spaces.URL" fails Support 2
D skip= in FOR /F fails Support 9
Joe Caverly Using a Directory Alias with @iniwrite fails Support 14
A WAD Output redirection to IF block fails with "unbalanced brackets" Support 7
E My echo full file name to the clipboard fails now. Support 2
A Fixed (CMD compat) START /D fails to recognize the switch option. Support 3
B MKLINK requires admin - fails silently. Support 1
D Fixed Take Command 21.0.29 fails – MSVCP140.dll missed Support 6
F Powershell call fails with "Scripting Integrator 2016 (PowerShell)" license error Support 9 Version 21.23 fails to install Support 4
D unzip fails to find valid license Support 3
StarliteLemming Fileread fails on Unicode file Support 10

Similar threads