我有一堆rar文件,其中一些只包含一个或多个文件,还有一些文件具有A目录结构
我想创建一个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脚本,将这个清单输出到一个临时文本文件read it find / pattern match .D.....测试该目录是否存在&测试文件是否存在
然后创建另一个bath文件来解压缩这些文件
但我想知道有没有更简单的方法?
谢谢
发布于 2012-11-21 06:12:29
您可以从一个批处理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\"
)
)这将对当前目录中的每个*.rar文件执行UnRAR.exe l filename,然后检查它是否包含字符串.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\"
)
)https://stackoverflow.com/questions/13480375
复制相似问题