我需要一些批处理脚本的帮助。 我使用7zip命令行将每个rar文件(jpg文件)的输出发送到文本文件" 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
contents.txt的输出是:
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
A * .jpg来自aa.rar,B * .jpg文件来自bb.rar,反之亦然。我试图读取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
for /f "usebackq delims=" %%i in (contents.txt) do (
set test="%%i"
echo %test%
)
)
PAUSE
但它不起作用。任何人都可以帮助我,我在这里做错了什么? echo%test%输出" test",而不是文本的内容。我是批处理脚本编程的新手,所以请原谅我的愚蠢。我想要以下输出:
aa.rar A01.jpg
bb.rar B01.jpg
cc.rar C01.jpg
答案 0 :(得分:2)
原始命令7z ...
生成输出
2001-07-17 08:39:00 ....A 326196 326164 A01.jpg
有趣的子串是#6(A01.jpg)。您可以在for /f
循环中处理输出并提取令牌#6。然后为其添加文件名。
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
)
)