1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

NEED HELP writing a batch file for the following task:

Discussion in 'Windows - Software discussion' started by aweathe, May 9, 2007.

  1. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    Hello,

    Does anyone know if it is possible to use a batch file for the following action?:

    Decompress a large number of winRAR files stored in a list of folders and subfolders.

    Thanks so much for any help offered! Also, I’m a windows XP user.

    Andrew
     
  2. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,485
    Likes Received:
    0
    Trophy Points:
    46
    How are the winrar files stored? Ae they all over the place, or are they in subfolders of one folder on on drive, or a mixture? Is it possible to get a list that might look like this -

    c:\archive\scripts\script1.rar
    c:\archive\scripts\script2.rar
    c:\archive\scripts\script3.rar
    c:\archive\docs\doc1.rar
    c:\archive\docs\doc2.rar
    c:\archive\docs\doc3.rar?

    I don't mean post it on here, I mean is it theoretically possible? Do you know how to do that?


     
  3. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    How the winRAR files are stored:

    There is a folder containing about 30 subfolders. In each of these 30 subfolders there is between 5-10 different folders, and in these folders is where the winRAR files are stored. There are about 1-3 winRAR files in each of these folders.

    As for the list format you suggested. Yes it is possible to get it in that format (I'm just learning batch files and don't think it would be too hard)... However I need the folders in the original format at the end. If the winRAR files were in the format you suggested then I would just select them all the decompress...

     
  4. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,485
    Likes Received:
    0
    Trophy Points:
    46
    So you want to extract the contents of the RAR archives somewhere else, leaving the archive folders as they are?

    How about another folder tree whose structure follows the original one, except each rar archive is replaced by a subfolder named after it?



     
    Last edited: May 9, 2007
  5. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    Decompress in the folder they're in now. (in-place)
     
  6. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    Well it would be most useful to have them decompressed in place... is this possible?
     
  7. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,485
    Likes Received:
    0
    Trophy Points:
    46
    In place, somewhere else, it's easy either way (famous last words!)... Do you want to keep the archives or delete them once their contents are extracted?


     
  8. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    I would like to keep the archives where they are.

     
  9. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,485
    Likes Received:
    0
    Trophy Points:
    46
    [​IMG]

    So the layout is like this?

    Spec check...

    Are you hoping for a batch file which could be run from Top Folder, which would result in all the RAR contents being extracted to the same sub-sub-folder where they are located? Without deleting the RARs?

    Expect trial version tomorrow...


     
  10. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    Yes that's the folder structure exactly! And "yes" is the answer to your last two questions. ie: I would like to keep the archives in the same place and have them extracted in the same place.

    Thanks! I'll just wait for your post!
     
  11. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    and also the file can be run from the Top folder in the diagram you posted.
     
  12. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,485
    Likes Received:
    0
    Trophy Points:
    46
    I am presuming that you have Rar.exe, the command-line program that comes along with WinRAR, and that its location is

    C:\Program Files\WinRAR\Rar.exe

    The version number would be helpful

    Code:
    C:\Program Files\WinRAR>rar /?
    RAR 3.70 beta 1   Copyright (c) 1993-2007 Alexander Roshal   8 Jan 2007
    Registered to Mike
    (etc)
    
     
    Last edited: May 9, 2007
  13. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    Yes the directory where winRAR is located is correct. my version is 3.62, but could download a more recent one if necessary. I have only the evaluation copy as well.
     
  14. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,485
    Likes Received:
    0
    Trophy Points:
    46
    copy this to Notepad & save as a batch file in the "Top folder" we discussed earlier.
    [pre]
    @echo off
    REM place this batch file in the top folder
    REM and run it from there
    if exist "%temp%\rardirlist.txt" del "%temp%\rardirlist.txt" > nul
    if exist "%temp%\subdirlist.txt" del "%temp%\subdirlist.txt" > nul

    REM remember where we are
    set topfolder=%CD%

    REM get a list of all the subfolders
    REM under this one and put it in
    REM a temp file
    dir /b /s /ad > "%temp%\subdirlist.txt"

    REM in a loop check each one for presence of
    REM rar files, write folder name to another list
    REM if any found
    for /F "delims==" %%a in (%temp%\subdirlist.txt) do (
    cd %%a
    if exist *.rar echo %%a >> "%temp%\rardirlist.txt"
    )

    REM for each folder that contains RARs
    REM cd to that folder and extract
    for /F "delims==" %%a in (%temp%\rardirlist.txt) do (
    cd %%a
    "c:\program files\winrar\rar.exe" e *.rar
    )

    REM clean up
    del "%temp%\subdirlist.txt" > nul
    del "%temp%\rardirlist.txt" > nul

    REM go back to where we were
    cd %topfolder%
    [/pre]
     
    Last edited: May 10, 2007
  15. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    unfortunately it didn't work on the first trial... hmmm I'm reading it and trying to figure it out so that I can fix it, but I'm just not there yet in the understanding!

    Maybe this with clarify; I have copied the output that I recieved in the command promt after running the file from there. (I named your file "winRAR.bat"). OK here it is:


    C:\Documents and Settings\ANDREW\Desktop\Assign 1>winRAR.bat
    The system cannot find the file C:\DOCUME~1\ANDREW\LOCALS~1\Temp\rardirlist.txt.

    Could Not Find C:\DOCUME~1\ANDREW\LOCALS~1\Temp\rardirlist.txt

    C:\Documents and Settings\ANDREW\Desktop\Assign 1>
     
  16. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,485
    Likes Received:
    0
    Trophy Points:
    46
    try this... creates and destroys temp files in the TOP folder

    [pre]
    @echo off
    REM place this batch file in the top folder
    REM and run it from there

    if exist "rardirlist.txt" del "rardirlist.txt" > nul
    if exist "subdirlist.txt" del "subdirlist.txt" > nul

    REM remember where we are
    set topfolder=%CD%

    REM get a list of all the subfolders
    REM under this one and put it in a temp file
    dir /b /s /ad > "subdirlist.txt"

    REM in a loop check each one for rar files
    REM write folder name to another list if any found
    for /F "delims==" %%a in (subdirlist.txt) do (
    cd %%a
    if exist *.rar echo %%a >> "rardirlist.txt"
    )

    REM for each folder that contains RARs
    RE enter folder and extract
    for /F "delims==" %%a in (rardirlist.txt) do (
    cd %%a
    "c:\program files\winrar\rar.exe" e *.rar
    )

    REM clean up
    del "subdirlist.txt" > nul
    del "rardirlist.txt" > nul

    REM go back to where we were
    cd %topfolder%

    [/pre]
     
  17. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    I'm looking over this myself right now... but here's the error message I got this time in the cmd promt (this time your file is labeled "winRAR2.bat" :


    C:\Documents and Settings\ANDREW\Desktop\Assign 1>winRAR2.bat
    'RE' is not recognized as an internal or external command,
    operable program or batch file.
    The system cannot find the file rardirlist.txt.
    Could Not Find C:\Documents and Settings\ANDREW\Desktop\Assign 1\9-Dec-2006\I57U
    S\subdirlist.txt
    Could Not Find C:\Documents and Settings\ANDREW\Desktop\Assign 1\9-Dec-2006\I57U
    S\rardirlist.txt

    C:\Documents and Settings\ANDREW\Desktop\Assign 1>
     
  18. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    Oh and I fixed the "RE" to "REM"
     
  19. aweathe

    aweathe Member

    Joined:
    May 9, 2007
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    16
    I'm not sure of the difference (or if it matters) but it's written ">>" instead of ">" about halfway down the script.
     
  20. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,485
    Likes Received:
    0
    Trophy Points:
    46
    yes, >> appends to file if it already exists, or creates a new one if it doesn't, whereas > always creates a new one.

    Getting there!
     

Share This Page