How to rename and extract all file?

Posted on

QUESTION :

Looking for a .bat to rename and extract all.
The folder is d:EJ%dd%-%mm%-%yyyy% (multiple files)

  • K02699_ej.zip
  • K02702_ej.zip
  • K02703_ej.zip
  • K02704_ej.zip
  • K02705_ej.zip

Rename to

  • K02699.zip
  • K02702.zip
  • K02703.zip
  • K02704.zip
  • K02705.zip

and then extract all

for /f "tokens=1,2 delims=_" %%i in ('dir/b *_ej.zip') do ren %%i_%%j %%i.zip
for %%i in (*.zip) do 7z x %%i -o

ANSWER :

Don’t see why it was so hard to figure out the minor changes you required:

for /f "tokens=1,2 delims=_" %%i in ('dir/b *ej.zip') do ren %%i_%%j %%i.zip
for %%i in (*.zip) do 7z x %%i -o%%~ni

If you don’t want to extract each archive to a separate sub-dir, just remove the -o argument.

Leave a Reply

Your email address will not be published. Required fields are marked *