batch-file - 仅知道扩展名时如何删除 .part1.rar、part01.rar 等
问题描述
这段代码应该删除成功提取的档案,首先是已知的%fullpath%\%file%.%exe%
. 它使用???
通配符,因此它会删除多部分,如.7z.001
,.zip.001
和.r01
,但它不能执行多部分,如.part1.rar, .part01.rar, .part001.rar
.
echo successfully unpacked "%fullpath%\%file%.%ext%"
attrib -r "%fullpath%\%file%.???"
for /r "%fullpath%" %%r in (%file%.???) do del "%%r" && echo deleted "%%r"
解决方案
我得到了它
echo unpacked "%fullpath%\%file%.%ext%"
attrib -r "%fullpath%\*.*" /s
:: maybe a little more concern here? also deletes every other filetype with the same name
for /r "%fullpath%" %%r in (%file%.??? %file:~0,-6%.part?.rar %file:~0,-7%.part??.rar %file:~0,-8%.part???.rar) do (
if exist "%%r" del "%%r" >nul 2>nul && echo deleted extracted archive "%%r")