Please Notice: For fastest support from PowerArchiver team, contact us via our Support page

Extracting only 1st file in a directory of archives



  • Hi guys, I have a problem:

    I have a list of rar files in a folder, but I would like to have ONLY the 1st file in each rar to be extracted to a folder. The first file is designated by its name, which is not standard/constant throughout all of the rars. Basically, whatever the name is of the first file, I would like it extracted. Is there any way to direct paext to do such a thing? Thanks alot!



  • There is no “first file” in an archive.

    How do you determine which is the “first file” you want to extract - by name (alphabetically) or by date (created, modified or … ) or by file size (largest, smallest) or some other way?



  • it would be first by name, sorry.



  • It may be possible to create a batch file to do this - but it would be non-trivial, my batch knowledge is not good enough 😞

    However, I just realised another problem with your scenario: you stated that these are rar archives. If they have been compressed as “solid” archives, then extracting a single file is not possible anyway, you always have to extract everything from a solid archive.



  • I have basic batch scripting experience, but I have been trying. Also, the rar’s are not solid, so it can be specified which files to extract.
    So far, I have:
    1. paext generating a list of the contents of each rar and outputting to a text file.
    2. head.bat (a batch that reads in the 1st line from a text file) to send to another text file.
    3. paext again to read in the first file name from the previous text file and extract only that file.
    4. it does work, but what I need now is to somehow incorporate this process in a for loop so it’s done automatically to all rars in a directory

    here is my wack-ass code lol:

    for /d %%X in (DIR) do call cc2.bat

    [cc2.bat]
    c:
    cd c:\pacl
    paext -v -d “DIR*.cbr” | find /i “.jpg” > x:\temp.txt && call x:\head.bat 1 x:\temp.txt > x:\firstfile.txt
    paext -px:\temp “DIR” @x:\firstfile.txt
    ^-output directory

    What happens is that it only extracts the 1st file from the 1st archive, i.e. it doesn’t go through all of the archives



  • Isn’t [for /d] working with folders and not files?



  • I also think you need to sort the list output (just in case) depending on required ouptut.

    Something like:-
    {For each cbr file call cc2}
    for %%X in (DIR*.CBR) do call cc2.bat %%x

    and use passed variable in cc2 -

    paext -v %x | sort > x:\temp.txt
    call x:\head.bat 1 x:\temp.txt > x:\firstfile.txt
    paext -px:\temp %x @x:\firstfile.txt

    Not sure what you are using find for??



  • find is to extract only the .jpg’s in the output from paext -v, as it gives other info in the output


  • Alpha Testers

    Old thread I know, but I find the problem described here very interesting.

    @TBGBe:

    How do you determine which is the “first file” you want to extract - by name (alphabetically) or by date (created, modified or … ) or by file size (largest, smallest) or some other way?

    @Infina:

    it would be first by name, sorry.

    The problem here is that like TBGBe says there are no first file in the archive. Infina, you say that it would be first by name, but the problem is that you don’t know which file that will be first in the list, resulting in that the name of the file won’t matter if it’s always the first file in the file list of the archive.

    If the name would be the first name in alphabetical order, then you would have to read the whole file list from the archive and then sort the names in alphabetical order to find the file name that would be the first file in this case.

    The next problem is that an archive can have multiple files with same name, but in different folders. If that happens, which file would be the first to extract?

    If you always are going to extract the first file that is in the file list of the archive, how do you know that it’s the correct file?

    Example: first add the file Z-TEXT.txt to Archive Test.zip and then add the file A-TEXT.txt to the same archive.

    If I then list the contents of Test.zip the file Z-TEXT.txt will appear first in the list, but how do you know that this is the correct file and not A-TEXT.txt

    The functionality you are asking for can be fixed, but not without your definition of “first file”.

    Kind Regards
    Micke



  • And don’t forget the possibility of same name with different file extension e.g. Z.txt, Z.jpg, Z.ini (etc)


Log in to reply
 

Looks like your connection to PowerArchiver Forums was lost, please wait while we try to reconnect.