uses dos; var f, out: file; bat: text; name, cname, tname: string; count, i, r: word; t: real; counter, size, chunks: longint; c: char; x: boolean; b: array[1..32768] of byte; code: integer; temp : string; function firstname(ile: string): string; var i : byte; begin i := pos( '.', ile); firstname:= copy(ile, 1, i); end; function ext(number: word): string; var s: string; begin if number > 999 then halt; str(number, s); case number of 0..9: ext := '00' + s; 10..99: ext := '0' + s; 100..999: ext := s; end; end; function fe(filename: string): boolean; var f : file; begin assign(f,filename); reset(f,1); close(f); fe := (ioresult = 0) and (filename <> ''); end; begin {clrscr;} name := ''; name := paramstr(1); if (name='/?') or (name='?') or (name='-?') or (name='help') then begin writeln('SPLIT'); writeln; writeln('Creates n file chunks depending on the chunk size you specify.'); writeln('USE: split [filename] [size] [/b]'); writeln; writeln(' filename: file you wish to split.'); writeln(' size: chunk size in kilobytes.'); writeln(' /b: forces size declaration in bytes.'); halt(0); end; if paramcount = 0 then begin write('File: '); readln(name); end; if not fe(name) then halt(1); assign(f, name); reset(f, 1); writeln('File size is ', filesize(f), ' bytes'); if paramcount < 2 then begin {writeln('Reminder: a floppy contains 1440 Kb. Single density: 720 Kb.'); writeln;} write('Chunk size in kilobytes [1400]: '); { readln(size); old} readln(temp); val(temp,size,code); if temp = '' then size := 1400; end else begin val(paramstr(2), size, code); { if code <> 0 then halt(0);} end; if size = 0 then begin writeln('Error in size!'); halt(1); end; if size < 10 then begin writeln('Error: chunk size must be greater than 10 kb!'); halt; end; if (paramstr(3) <> '/b') and (paramstr(3) <> '/B') then begin size := size * 1024; {aha! 1 kb = 1024 byte, not 1 kb = 1000 byte!} end else if size < 10240 then begin writeln('Error: chunk size must be greater than 10 kb!'); halt; end; t := filesize(f) / size; if t = trunc(t) then chunks := trunc(t) else chunks := trunc(t) + 1; if chunks = 1 then begin writeln('Error: chunk size is too large!'); halt; end; writeln('I will output ', chunks, ' chunks.'); tname := firstname(name) + 'bat'; writeln('Use ', tname, ' to put chunks back together.'); for i := 1 to chunks do begin cname := firstname(name) + ext(i); writeln(' ', cname); assign(out, cname); rewrite(out, 1); x := false; counter := size; count := 32768; {report size of array in declaration} repeat {blockread(f, c, 1, r); blockwrite(out, c, 1, r); this works} if counter < count then count := counter; blockread(f, b, count, r); blockwrite(out, b, r, r); counter := counter - r; {end of optimization} if filepos(out) = size then x := true; if eof(f) then x := true; until x; close(out); end; close(f); {batch file} assign(bat, tname); rewrite(bat); write(bat, 'copy /b '); counter := 0; for i := 1 to chunks do begin cname := firstname(name) + ext(i); write(bat, cname); if i < chunks then if i- counter = 3 then begin writeln(bat, ' '+name+ ' /v'); write(bat, 'copy /b '+ name); counter := i; end; if i < chunks then write(bat, '+'); end; writeln(bat, ' ', name, ' /v'); close(bat); end.