2

I have the following batch script, iterating recursively on all files in a given folder:

FOR /R %%i IN ("*.wmv") DO "C:\Program Files\7-Zipa\7za.exe" a -mx0 -tzip -pPassword -mem=AES256 -y "%%~dpni.zip" "%%i"

that, when ran, it produces the following output per each file it works on:

 7-Zip (a) [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04

 Scanning the drive:
 1 file, 382316 bytes (374 KiB)

 Creating archive: C:\test\7208969.zip

 Items to compress: 1


 Files read from disk: 1
 Archive size: 382524 bytes (374 KiB)
 Everything is Ok

What I would like is to create an output text file that only contains these two lines per iteraction:

Creating archive: C:\test\7208969.zip
Everything is Ok

I've tried calling the main batch script from another batch using something like (this is just an illustrative example):

FOR /F "(tried with skip, delims, tokens, etc)" %%G IN ('7zip.bat') DO echo %%G

but all that I've tried ended up writing lots of weird stuff, except what I needed.

If anyone could enlighten me on how to accomplish this in any way, it'll be much appreciated!.

1 Answer 1

1

just pipe the output of your command in your loop with findstr and 2 expressions, one for each line.

FOR /R %%i IN ("*.wmv") DO "C:\Program Files\7-Zipa\7za.exe" a -mx0 -tzip -pPassword -mem=AES256 -y "%%~dpni.zip" "%%i" | findstr /C:"Creating archive" /C:"Everything"

At this point, I don't have the case where something goes wrong. Obviously you can add as many strings as you want:

... | findstr /C:"Creating archive" /C:"Everything is OK" /C:"Something went wrong"
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a million!. You totally nailed it and with the outmost simplicity! =). One thing that happened when I tried it is that if I use "Creating archive" it will not output that line, but when only using "Creating", it works like a charm.
Totally!. Sorry I didn't accept it before, I'm kinda new to this community. Thanks again! =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.