Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: batch file to unrar one file from more archives to different folders  (Read 15048 times)

0 Members and 1 Guest are viewing this topic.

yavvie

    Topic Starter


    Rookie

    Hi,
    I need to unrar one file from a lot of archives, but each of them to a separate directory. The second problem is that I dont want to unrar the file to its original directory structure.
    Here is my problem:
    I have a list of archives with structure such as
    Archive20080131.rar
       --> folders in archive FolderA, FolderB, FolderC
          --> i need one file File.bak from FolderB
    i need to unpack File.bak directly into a directory called Archive20080131 (ignoring the other subfolders in the archive)

    The folder Archive20080131 is already created from a previous use.

    My names of archives are created using current date, so the name does not increase by any constant number. And I have a new archive for every day, so now i'd need to unpack about 200 of them :)
    I need to write the batch file to take the name of the archive into a variable and use it as the name of the destination folder (but it just doesnt work for me), can anyone help?

    Dias de verano

    • Guest
    Re: batch file to unrar one file from more archives to different folders
    « Reply #1 on: March 21, 2008, 08:20:41 AM »
    What unrar program will you be using?

    yavvie

      Topic Starter


      Rookie

      Re: batch file to unrar one file from more archives to different folders
      « Reply #2 on: March 21, 2008, 08:30:18 AM »
      i have winrar, but i need to write it as a batch program

      Dias de verano

      • Guest
      Re: batch file to unrar one file from more archives to different folders
      « Reply #3 on: March 21, 2008, 08:32:31 AM »
      So will you be using the rar.exe command line program that comes with WinRar?

      patio

      • Moderator


      • Genius
      • Maud' Dib
      • Thanked: 1769
        • Yes
      • Experience: Beginner
      • OS: Windows 7
      Re: batch file to unrar one file from more archives to different folders
      « Reply #4 on: March 21, 2008, 08:33:49 AM »
      If i remember WinRar has this ability to span archives built in...but i no longer have it installed.
      " Anyone who goes to a psychiatrist should have his head examined. "

      yavvie

        Topic Starter


        Rookie

        Re: batch file to unrar one file from more archives to different folders
        « Reply #5 on: March 21, 2008, 08:35:10 AM »
        yes, i'll use the unrar command (if i remember correctly) coming with rar.exe

        Dias de verano

        • Guest
        Re: batch file to unrar one file from more archives to different folders
        « Reply #6 on: March 21, 2008, 08:52:07 AM »
        I do not think you can flatten out the folder structure when extracting from an archive created with one, so i think you will have to extract the tree including the folder with the file you want (it will contain just that file) -- into a temp folder -- and then move the file where you want it and finally delete the extracted tree.

        You can use the FOR variable modifiers to get the archive name minus extension and use that to create the folder name.



        yavvie

          Topic Starter


          Rookie

          Re: batch file to unrar one file from more archives to different folders
          « Reply #7 on: March 21, 2008, 09:03:56 AM »
          can you put here some script to do the folders with the name of the archive? because i always get the rar in the folder name :( and it also doesnt go through all the archives... I'm still kinda lame with batch programming...

          Dias de verano

          • Guest
          Re: batch file to unrar one file from more archives to different folders
          « Reply #8 on: March 21, 2008, 09:09:43 AM »
          Code: [Select]
          FOR /F "delims==" %%R in ('dir /b *.rar') do (
             echo complete filename     %%R
             echo filename no extension %%~nR
          )


          Dias de verano

          • Guest
          Re: batch file to unrar one file from more archives to different folders
          « Reply #9 on: March 21, 2008, 09:56:28 AM »
          Try this.

          Assumes the RAR files are all in the same folder. The created folders will be within (under) that folder. Any path or file name that contains spaces (or may do) should be quoted.

          Code: [Select]

          @echo off
          FOR /F "delims==" %%R in ('dir /b *.rar') do (
             MD "%%~nR"
             unrar x "%%R" FolderB\File.bak
             move FolderB\File.bak "%%~nR"
             rd FolderB
             )



          yavvie

            Topic Starter


            Rookie

            Re: batch file to unrar one file from more archives to different folders
            « Reply #10 on: March 21, 2008, 10:41:40 AM »
            and if i need to create the new folder on a different disk? if i have the .rar on U: and need to extract them to Y:

            Dias de verano

            • Guest
            Re: batch file to unrar one file from more archives to different folders
            « Reply #11 on: March 21, 2008, 11:42:55 AM »
            MD is the make folder command and %%~nR is the folder name derived from the archive name so just add drive letter etc

            @echo off
            FOR /F "delims==" %%R in ('dir /b *.rar') do (
               MD "Y:\path to\your folder\%%~nR"
               unrar x "%%R" FolderB\File.bak
               move FolderB\File.bak "Y:\path to\your folder\%%~nR"%%~nR"
               rd FolderB
               )

            yavvie

              Topic Starter


              Rookie

              Re: batch file to unrar one file from more archives to different folders
              « Reply #12 on: March 25, 2008, 03:46:06 AM »
              all i got from this one is a cycle that kept on creating the same folder (and printing errors that the folder already existed), and it never extracted anything, nor moved to the next .rar :(

              Dias de verano

              • Guest
              Re: batch file to unrar one file from more archives to different folders
              « Reply #13 on: March 25, 2008, 05:44:35 AM »
              is unrar.exe available to the batch file?

              yavvie

                Topic Starter


                Rookie

                Re: batch file to unrar one file from more archives to different folders
                « Reply #14 on: March 25, 2008, 05:46:50 AM »
                how do i check?
                but even if it wasnt, i would expect some error instead of the infinite loop...