I'm trying to delete some files in a WinRar Archive using the Command Line.
The Rar-File:
/testing.rar
/testing.rar/some-data.txt
/testing.rar/testing/some-data.txt
Here's my Code:
cd "C:\Program Files\WinRAR\" && rar d -cl -r "c:\full\path\testing.rar" some-data.txt
It only deletes the some-data.txt file in the root, not inside /testing/
When using
cd "C:\Program Files\WinRAR\" && rar d -cl -r "c:\full\path\testing.rar" some-data.*
(changed the extension to .*) it does delete both files.
Am I doing something wrong?
While the d
command can not handle it, a simple pipe can deal with it
@echo off
setlocal enableextensions disabledelayedexpansion
set "rar=C:\Program Files\WinRar\rar.exe"
set "archive=c:\full\path\testing.rar"
(
%= List archive contents =%
"%rar%" lb -ed "%archive%"
)|(
%= filter the list for the file in any subfolder =%
findstr /i /e /l /c:"\somedata.txt"
%= and include the root file =%
echo somedata.txt
)|(
%= Delete from archive the list of files read from stdin =%
"%rar%" d -cl -n@ "%archive%"
)
The second step (filter the list of files in archive) is splited in the findstr
and the echo
just to prevent the case when the file to be deleted is not present in the output. Without a list of files the -n@
modifier (read files to delete from stdin
) will not read anything and all the archive contents will be removed.