Zip and Delete Directory in Loop using Batch Comma

2019-08-11 11:05发布

问题:

I have a batch command. As it follows. It can zip directories in other directory.

@echo off
    set "zip=7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on"
    set "directory=C:\SqlData\BackUpData"
    for /d %%i in ("%directory%\*") do %zip% "%%~fi.7z" "%%~fi\*"

I want to add one more line. It should delete original file after zipped. Thanks.

回答1:

If I understand you correctly, I think this is the line you're looking for:

for /d %%i in ("%directory%\*") do del "%%~fi\*.*" /q