So I've got a lot of archived (rar) files with par2 recovery files associated with them, and my goal is to write a program that will do its work in the present working directory.
the par2 files are either labeled filename.volume.PAR2, filename.volume.par2, filename.par2, or filename.PAR2.
The first run should check the entire contents of the directory to see which format has been used for the file exension, and then dump its results into an array of strings, or a file, or something for use later.
The second run then needs to check the entire directory for the format of the rar files. The first archive is labeled as either filename.r00, filename.R00, or filename.part01.rar, and dump the contents to an array of strings or something for use later.
with the formats for the extension collected, the next step should truncate the results to PAR2, par2, or both.
Code:
if(par2 && PAR2 are present)
then execute par2 v *.par2
then execute par2 v *.PAR2
else if(par2 && !PAR2)
then execute par2 v *.par2
else if(!par2 && PAR2)
then execute par2 v *.PAR2
very near the end of the output of par2 v *.whatever, a status message is printed which states whether or not recovery is required. That needs to be captured and used in a test to determine whether or not par2 needs to be executed with the r flag.
The best way, since if repair is necessary, the status message is printed 6 lines from the end, and when repair is unnecessary, the message is printed at the very end of the output, seems to me to be an on-the-fly evaluation of the output from the par2 v command.
Code:
if(Repair is required.)
then execute par2 r *.whatever
else if(All files are correct, repair is not required.)
then move on to extraction
Code:
if(Repair is required. && par2 && PAR2)
then execute par2 r *.par2
then execute par2 r *.PAR2
else if(Repair is required. && par2 && !PAR2)
then execute par2 r *.par2
else if(Repair is required. && !par2 && PAR2)
then execute par2 r *.PAR2
So, once the par2 files are verified and repaired if necessary, then it is time to extract from the primary archive, the contents, into a newly created directory that is named "filename".
so,
Code:
if(.r00 && .R00 && .part01.rar)
then extract all of those to a directory labeled filename
else if(.r00 && !.R00 && !.part01.rar)
then extract just those ones to a directory labeled filename
else if(!.r00 && .R00 && !.part01.rar)
then extract just those ones to a directory labeled filename
else if(!.r00 && !.R00 && .part01.rar)
then extract just those ones to a directory labeled filename
My questions are --
How do I, from a C program, grab only a single instance of a file extension from multiple entries from an overall filename which may contain any number of different characters and formats?
IE -
2008.records.bak.PAR2
Home.films-09.par2
Extremely-long-list-of-ingredients.vol83-93.par2
END RESULT SHOULD BE -
.PAR2 && .par2
IE 2 -
huffinsmcpuffins.par2
twenty-8-steps_to.fall-asleep-tonight.par2
END RESULT SHOULD BE -
.par2 && !.PAR2
My initial thought is that I could do ls *.par2 *.PAR2 > pars
strip the filenames and only keep the file extensions
then uniq the file to reduce it to either par2, PAR2, or both.
How do I, from a C program, execute another program with a wildcard because the filename, at this stage, is unimportant for the par2 command, followed by one or both of 2 possible formats for the file extension.
IE -
with the previous results from either EX 1 or EX 2, do -
(what will be done regardless) [what needs to be added]
(par2 v *) [.par2]
(par2 v *) [.PAR2]
My initial thought is a loop that is iterated based on how many different formats of extensions there are. The trick would be to distinguish between either par2 or PAR2, if both weren't present, but at the moment I'm unsure as to how that might be achieved.
Next up is searching for the rar extensions. I imagine that the solution to doing it with par2 extensions would be mostly the same for the rars, so that's not my primary concern.
So, how do I strip the extensions from the output of a command like ls *.r00 *.R00 *.part01.rar, and then uniq what is left and use that for the creation of directories to extract the files in to?
IE -
test01.r00
test01.r01
test01.r02
test01.r03
test02.R00
test02.R01
test02.R02
test1-334-dd-4565.part01.rar
test1-334-dd-4565.part02.rar
test1-334-dd-4565.part03.rar
END RESULT IS -
mkdir test01
mkdir test02
mkdir test1-334-dd-4565
If I can get these questions answered, I can figure the rest out. It's not a matter so much as, "how do I do X", but moreso a matter of, "I've got the general idea, but some of it isn't quite clear to me. I mean, I could make it work for 20% of the cases, but not 100% of the cases... and that is unsatisfactory!"
Thanks guys, hope this post clearly conveyed my troubles.