home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
NEWS
/
554
/
MAI
/
SPLTFILE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-10-07
|
3KB
|
98 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 132 of 345
From : Eric Miller 1:387/307.0 23 May 93 20:58
To : Stephen Cheok
Subj : SPLITTING FILES
────────────────────────────────────────────────────────────────────────────────
quoted from carbon unit Stephen Cheok to All
about SPLITTING FILES on 05-21-93 16:26
SC> Hi! I was wondering. How would you in Turbo Pascal be able
SC> to split a single file into two. I want it to split it to a precise
SC> byte for both files. I want to be able to combine to files together
SC> and split it to its original sizes and still be able to work (that no
SC> codes are missing etc.). Help.. Thanx..
Well, what you do is read in parts of the original to the
first file to a certain point, and then from there write them
to the second file, and so on. the following code works, but
is terribly ineffecient, etc... }
PROGRAM SplitFile;
VAR
infile,
outfile1,
outfile2: File;
orig_size, readd, count,
buffer_size, file1_size, file2_size: longint;
pbuf: pointer;
orig_file, out_file1, out_file2: string;
BEGIN
Write('Enter original filename: ');
Readln(orig_file);
Assign(infile, orig_file);
Reset(infile,1);
orig_size := filesize(infile);
Write('Enter outfile 1 filename: ');
Readln(out_file1);
Write(' Enter size (',orig_size,' max): ');
Readln(file1_size);
Write('Enter outfile 2 filename: ');
Readln(out_file2);
Write(' Enter size (',orig_size-file1_size,' max): ');
Readln(file2_size);
Assign(outfile1, out_file1);
Rewrite(outfile1,1);
Assign(outfile2, out_file2);
Rewrite(outfile2,1);
{ init }
readd := 0;
buffer_size := 4096; { max bytes to read in at a time }
getmem(pbuf, buffer_size);
{ outfile1 }
WHILE (Readd < file1_size) DO
BEGIN
count := file1_size - readd; { bytes left to read }
IF count > buffer_Size then count := buffer_size; { too much for buf? }
Writeln('Reading ', count, ' bytes...');
Blockread(infile, pbuf^, count);
blockwrite(outfile1, pbuf^, count);
inc(readd, count);
END;
{ outfile1 }
readd := 0;
WHILE (Readd < file2_size) DO
BEGIN
count := file2_size - readd;
IF count > buffer_Size then count := buffer_size;
Writeln('Reading ', count, ' bytes...');
Blockread(infile, pbuf^, count);
blockwrite(outfile2, pbuf^, count);
inc(readd, count);
END;
Close(infile);
Close(outfile1);
Close(outfile2);
END.