Below is a script I've used in the past for a similar task with 100% success that is pure batch with 7Zip where you can explicitly specify the source directory where it can be a drive letter or folder.
This also allows you to explicitly specify an initial root temp directory and then create a new folder within it matching the name of the zip file minus the zip extension, and then removes it once the 7Zip archive operations are complete for each zip file the For /F loop iterates and processes.
You just set the values of the
z7= variable to be whatever they need to be in your environment at the top of the script and the rest will just work.
You can specify whatever 7Zip compression methods you need at the end of the
%z7% a ~ command right after the
-aoa switch like
-aoa -m<method_parameters> for your needs.
To run as a batch script though, save the logic to a text document on your desktop, etc. as
<something>.cmd from the text document file | save options. Once saved, just double-click it to execute the logic (or right click run as administrator), and confirm the files have been manipulated as expected afterwards.
SET z7="C:\Program Files\7-Zip\7z.exe"
FOR /F "usebackq tokens=*" %%a IN (`DIR /S /B /A-D "%Src%\*.zip"`) DO (
IF NOT EXIST "%ExtractDir%\%%~Na" MD "%ExtractDir%\%%~Na"
ECHO A | %z7% e "%%~Fa" -o"%ExtractDir%\%%~Na" -r
%z7% a "%%~Fa" "%ExtractDir%\%%~Na\*" -aoa
RD /Q /S "%ExtractDir%\%%~Na"
Please note the
ECHO A | in front of the
%z7% e ~ command to tell it to overwrite any existing files that exist in the out directory rather than waiting on you to tell it to do so, etc.
Also, please note the use of the
-aoa switch at the end of the
%z7% a ~ command which tells it to overwrite all existing files within the zip file you are zipping to replacing all original files within it without actually deleting the entire original zip file beforehand which is very simple to add to this script if needed by one additional line of
IF EXIST "%%~Fa" DEL /Q /F "%%~Fa".
- For /F
%~fI - expands %I to a fully qualified path name
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only