我有一堆rar文件,其中一些只包含一个或多个文件,一些有一个目录结构
我想创建一个bat文件,可以使用该目录解压缩rar&如果没有目录使用rar文件名来创建目录&然后提取到那个处理任何错误的课程
所以这个cmd会将一个列表输出到文本文件
C:\Program Files\WinRAR>UnRAR.exe l H:\temp\test.rar >H:\temp\test.txt
结果
UNRAR 4.20 freeware Copyright (c) 1993-2012 Alexander Roshal
Archive H:\temp\Test.rar
Name Size Packed Ratio Date Time Attr CRC Meth Ver
-------------------------------------------------------------------------------
Test.TXT 0 0 0% 20-11-12 18:44 .....A. 00000000 m0b 2.9
-------------------------------------------------------------------------------
1 0 0 0%
表示没有目录结构的rar文件和
UNRAR 4.20 freeware Copyright (c) 1993-2012 Alexander Roshal
Archive H:\temp\testDir.rar
Name Size Packed Ratio Date Time Attr CRC Meth Ver
-------------------------------------------------------------------------------
Test.TXT 0 0 0% 20-11-12 18:44 .....A. 00000000 m0b 2.9
test 0 0 0% 20-11-12 18:45 .D..... 00000000 m0 2.0
-------------------------------------------------------------------------------
2 0 0 0%
目录
我可以创建一个perl脚本,将此列表输出到临时文本文件,读取它/模式匹配.D .....测试该目录是否存在&测试文件是否退出
然后创建另一个浴室文件以提取文件
但我想知道是否有更简单的方法?
感谢名单
答案 0 :(得分:1)
你可以从这样的批量scrpit开始:
@echo off
setlocal EnableDelayedExpansion
for %%a in (*.rar) do (
UnRAR.exe l "%%a" | findstr /C:".D....." >nul
if !errorlevel!==0 (
echo File %%a contains dirs
UnRAR.exe x "%%a"
)
if !errorlevel!==1 (
echo File %%a does not contain dirs, extracting in %%~na
mkdir "%%~na"
UnRAR.exe x "%%a" "%%~na\"
)
)
这将对当前目录中的每个UnRAR.exe l filename
文件执行*.rar
,然后检查它是否包含字符串.D.....
,如果字符串是,则在当前目录中提取rar找不到,否则它将创建一个与归档具有相同文件名的目录(但没有扩展名)并在那里提取归档。请检查我使用的UnRAR.exe的语法是否正确。
编辑:此代码以递归方式循环遍历子目录:
@echo off
setlocal EnableDelayedExpansion
for /r "%1" %%a in (*.rar) do (
UnRAR.exe l "%%a" | findstr /C:".D....." >nul
if !errorlevel!==0 (
echo File %%a contains dirs, extracting in "%%~dpa"
UnRAR.exe x "%%a" "%%~dpa"
)
if !errorlevel!==1 (
echo File %%a does not contain dirs, extracting in %%~dpna
mkdir "%%~na"
UnRAR.exe x "%%a" "%%~dpna\"
)
)