Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

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.

share|improve this answer
Thank you very much. And i have more questions. 1. If i have a folder name is changing every day such as d:\EJ\27-12-2012\ (d:\EJ\%dd%-%mm%-%yyyy%) how to put a path in batch file? –  Dheerapong Ountantaeyanont Dec 27 '12 at 2:30
Take a look at my answer here. –  Karan Dec 27 '12 at 14:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.