Menu

Par Rar script or batch

2003-08-13
2003-09-21
  • Nobody/Anonymous

    I just found par2 command line, and I am trying to write a batch or script to do the following:

    1. Find all par/par2 files in a directory.
    2. Repair
    3. Delete par/par2's only if successful
    4. Find all rars
    5. Extract
    6. Delete rars only if successful

    Anyone already do this?  I'm kind of stuck on the delete only if successful part.  I'm fairly new to this computer stuff.  The idea is easy to implement, right?  How do I do this?

     
    • Marco van Loon

      Marco van Loon - 2003-08-13

      unix: a program's exit code is stored in the $? variable. [1]
      DOS/windows commandline: a program's exit code is stored in the errorlevel variable

      par2cmdline seems to have an exit code of '0'
      on success and different non-zero numbers on different errors
      (as of yet undocumented unfortunately...)

      I don't know which exit codes the (un)rar program
      produces, so you'll have to find that out for yourself.

      [1] though the '||' and '&&' shortcuts can also be used (see 'man bash').
      par2 r .... && rm [par2 files]   should then also work.
      PS: par2 only works on a single par2 set at a time, so if you've got multiple par2 sets stored in
      the same directory, you'd have to loop over then with a 'for loop' or something like that...

      Marco van Loon

       
      • Peter C

        Peter C - 2003-08-13

        The exit codes for par2cmdline are fully documented in the source code.

        From par2cmdline.h you have the following:

        // Return type of par2cmdline
        typedef enum Result
        {
          eSuccess                     = 0,

          eRepairPossible              = 1,  // Data files are damaged and there is
                                             // enough recovery data available to
                                             // repair them.

          eRepairNotPossible           = 2,  // Data files are damaged and there is
                                             // insufficient recovery data available
                                             // to be able to repair them.

          eInvalidCommandLineArguments = 3,  // There was something wrong with the
                                             // command line arguments

          eInsufficientCriticalData    = 4,  // The PAR2 files did not contain sufficient
                                             // information about the data files to be able
                                             // to verify them.

          eRepairFailed                = 5,  // Repair completed but the data files
                                             // still appear to be damaged.

          eFileIOError                 = 6,  // An error occured when accessing files
          eLogicError                  = 7,  // In internal error occurred
          eMemoryError                 = 8,  // Out of memory

        } Result;

        If you "verify", then all return values are possible expect for 5. If you "repair", then all return values are possible except for 1.

        A return value of 0 when verifying means the files were ok to start with. A return value of 0 when repairing means either that the files were ok to start with, or that they were succesfully repaired.

         
    • Nobody/Anonymous

      In DOS, the exit code is read with ERRORLEVEL. You need to find out the ERRORLEVELS of the programs you use but often times non zero is an error and zero is success.

      IF ERRORLEVEL 1 GOTO SKIPDELETE
      DELETE SOME FILES
      :SKIPDELETE

      Opposite of you I am looking for ways to keep the PAR files. Just as the PAR file gets me the download that would have been discarded in the past, I want the same PAR files to protect the files on the media they go on.

       

Log in to post a comment.