-2

I need some help with batch scripting. I am using 7zip command line to send the output of each rar file (jpg files) to a text file "contents.txt"

set PATH=%PATH%;"C:\Program Files\7-Zip"

echo. > contents.txt
for /R %%f in ("*.*") do (
7z l -r "%%f" | FIND /V "ing " | FIND /V "Igor Pavlov" | FIND /V "--" | FIND /V "Path" | FIND /V "Type" | FIND /V "Solid" | FIND /V "Blocks" | FIND /V "Multivolume" | FIND /V "Volumes" | FIND /V "Date" | FIND /V "---" | FIND /V "Physical Size" | FINDSTR /R /E ".jpg" >> contents.txt
)
PAUSE

The output of contents.txt is :

2001-07-17 08:39:00 ....A       326196       326164  A01.jpg
2001-07-17 08:39:00 ....A       338338       338338  A02.jpg
2001-07-17 08:39:00 ....A       332076       332076  A03.jpg
2001-07-17 08:39:00 ....A       458422       458422  A04.jpg
2001-07-17 08:39:00 ....A       376821       376821  A05.jpg
2001-07-17 08:39:00 ....A       326196       326164  B01.jpg
2001-07-17 08:39:00 ....A       338338       338338  B02.jpg
2001-07-17 08:39:00 ....A       332076       332076  B03.jpg
2001-07-17 08:39:00 ....A       458422       458422  B04.jpg
2001-07-17 08:39:00 ....A       376821       376821  B05.jpg
2001-07-17 08:39:00 ....A       326196       326164  C01.jpg
2001-07-17 08:39:00 ....A       338338       338338  C02.jpg
2001-07-17 08:39:00 ....A       332076       332076  C03.jpg
2001-07-17 08:39:00 ....A       458422       458422  C04.jpg
2001-07-17 08:39:00 ....A       376821       376821  C05.jpg

The A*.jpg fies from aa.rar, the B*.jpg files are from bb.rar, and vice versa. I am trying to read the contents.txt file to get the first file name only. I modified the above script to:

for /R %%f in ("*.*") do (
7z l -r "%%f" | FIND /V "ing " | FIND /V "Igor Pavlov" | FIND /V "--" | FIND /V "Path" | FIND /V "Type" | FIND /V "Solid" | FIND /V "Blocks" | FIND /V "Multivolume" | FIND /V "Volumes" | FIND /V "Date" | FIND /V "---" | FIND /V "Physical Size" | FINDSTR /R /E ".jpg" >> contents.txt

for /f "usebackq delims=" %%i in (contents.txt) do (
set test="%%i"
echo %test%
)
)
PAUSE

but it does not work. Can anyone help me what am I doing wrong here? The echo %test% output "test", not the contents of text. I am new to batch script programming, so please excuse my stupidity. I want the following output:

aa.rar A01.jpg
bb.rar B01.jpg
cc.rar C01.jpg
user1492667
  • 139
  • 3
  • 13

1 Answers1

2

The original command 7z ... produces output

2001-07-17 08:39:00 ....A       326196       326164  A01.jpg

the interesting substring is #6 (A01.jpg). You can process the output in the for /f loop and extract the token #6. And then add a file name to it.

for /R %%A in ("*.*") do (
    rem  Loops through the output of the command  7z ...
    rem  and pass tokens (5th, remainder) as (%%B, %%C)
    for /f "tokens=5*" %%B in ('7z l -r "%%A" ^| FIND /V "ing " ^| FIND /V "Igor Pavlov" ^| FIND /V "--" ^| FIND /V "Path" ^| FIND /V "Type" ^| FIND /V "Solid" ^| FIND /V "Blocks" ^| FIND /V "Multivolume" ^| FIND /V "Volumes" ^| FIND /V "Date" ^| FIND /V "---" ^| FIND /V "Physical Size" ^| FINDSTR /R /E ".jpg"') do (
        echo %%A %%C>>contents.txt
    )        
)
Dmitry Sokolov
  • 3,118
  • 1
  • 30
  • 35