Originally Posted by
Perspective
>>Once I'm done I'll write some utility to concatenate files with consecutive names...
how bout cat ?
Didn't know it existed. Anyway, what a coincidence - that's what I called my utility. It was more specialised, as each sector's filename was the number of the sector it came off so the algorithm had to merge files with consecutive names and start a new file once the sequence was broken.
Code:
#include <iostream.h>
#include <string.h>
#include <stdio.h>
int main (void)
{
FILE *inFile;
FILE *outFile;
bool newFile = true;
int inFileNo;
int outFileNo = 1;
char inFileName [21];
char outFileName [21];
char path [21];
unsigned char currentByte;
cout << "File concatenator." << endl;
cout << "2005 Sam D, Gwilliam." << endl;
cout << "Enter Path: " << endl;
cin >> path;
for (inFileNo = 20200; inFileNo <= 9000000; inFileNo++) // Not the most efficient way but a quick fix.
{
// Generate new in filename and attempt open:
sprintf (inFileName, "%s%d.bin", path, inFileNo);
inFile = fopen (inFileName, "rb");
// If no file, then next infile number:
if (!inFile)
{
fclose (outFile);
if (!newFile)
{
newFile = true; // If no file found (i.e. sequence broken) start new out file.
cout << "Ended file " << outFileName << ", searching..." << endl;
}
continue;
}
// Otherwise success:
cout << "Successfully opened file " << inFileName << "." << endl;
// If this is the start of a sequence then create a new out file:
if (newFile)
{
sprintf (outFileName, "%s%d.txt", path, outFileNo++);
cout << "Adding to new file " << outFileName << "." << endl;
outFile = fopen (outFileName, "wb");
newFile = false; // Append this file from now on.
}
// Otherwise, add to the existing one:
else
cout << "Adding to existing file " << outFileName << "." << endl;
// Add to out file:
for (int fl = 0; fl < 512; fl++)
{
currentByte = fgetc (inFile);
fputc (currentByte, outFile);
}
fclose (inFile);
}
cout << "All done!" << endl;
return 1;
}