-1

I am looking for a simple batch or vbs script I can edit to complete the following tasks.

  1. Search a folder (including sub dirs) for *.rar files.
  2. Extract the *.rar found to a specific drive i.e E:/ or F:/ (I can change the file for this)
  3. The twist, is the script must rename the extracted file to the directory name.

i.e

C:\Documents\Shop1_A\file.rar

Inside file.rar there is a file.pdf

I require the script to extracted the file.rar to a drive and rename the extracted file to E:\Shop1_A.pdf

There will only ever be 1 file in the archive (no duplicate or overwrite errors)

  • Is there only 1 rar file in each directory / subdirectory? – Matt Williamson Dec 02 '13 at 11:40
  • 1
    SO is not the type of place where you specify your requirements and other people write code for you. What have you tried so far, and what **specific** problem do you need help with? – Ansgar Wiechers Dec 02 '13 at 12:09
  • Ansgar, I understand this. I have tried unrar and have fallen short, only able to extract the file but unable to get it renamed to the previous directorys name... – Lance Cuijpers Dec 04 '13 at 13:04

2 Answers2

1
set "sourceDir=c:\someware"
set "targetDir=f:\"
set "unrar=c:\program files\WinRar\unrar.exe"

for /r "%sourceDir%" %%f in (*.rar) do for /d %%d in ("%~dpf\.") do (
    "%unrar%" p -inul "%%~f" > "%targetDir%\%%~nd.pdf"
)
MC ND
  • 69,615
  • 8
  • 84
  • 126
0

do you only have pdf files? If not, try this:

@ECHO OFF &SETLOCAL
set "SourceFolder=%userprofile%"
set "DestinationFolder=%temp%"

for /d /r "%SourceFolder%" %%a in (*) do for %%b in ("%%~fa\*.rar") do for /f "delims=" %%c in ('rar lb "%%~Fb"') do (
    rar e -idq "%%~fb" "%%~c" "%DestinationFolder%"
    ren "%DestinationFolder%\%%~c" "%%~na%%~Xc"
)

If you don't own rar, you can also work with the free unrar.

Endoro
  • 37,015
  • 8
  • 50
  • 63