Regular expression to match only the first file in a RAR file set

后端 未结 4 823
半阙折子戏
半阙折子戏 2021-01-16 00:39

To see what file to invoke the unrar command on, one needs to determine which file is the first in the file set.

Here are some sample file names, of which - naturall

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-16 00:56

    Don't rely on the names of the files to determine which one is first. You're going to end up finding an edge case where you get the wrong file.

    RAR's headers will tell you which file is the first on in the volume, assuming they were created in a somewhat-recent version of RAR.

    HEAD_FLAGS Bit flags:
    2 bytes

    0x0100 - First volume (set only by RAR 3.0 and later)

    So open up each file and examine the RAR headers, looking specifically for the flag that indicates which file is the first volume. This will never fail, as long as the archive isn't corrupt. I have done my own tests with spanning RAR archives and their headers are correct according to the link above.

    This is a much, much safer way of determining which file is first in a set like this.

提交回复
热议问题