home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff339.lzh / PCQ / Examples / Copier.p < prev    next >
Text File  |  1990-03-19  |  1KB  |  61 lines

  1. Program Copier;
  2.  
  3. {
  4.     This is a simple program to exercise DOS a bit.  It just
  5. copies one file to another, using DOSRead and DOSWrite.
  6. }
  7.  
  8. {$I ":Include/DOS.i"}
  9. {$I ":Include/Ports.i"}
  10. {$I ":Include/Parameters.i"}
  11. {$I ":Include/StringLib.i"}
  12.  
  13. var
  14.     InputFileName  : String;
  15.     OutputFileName : String;
  16.     Position       : Integer;
  17.     Infile         : FileHandle;
  18.     Outfile        : FileHandle;
  19.     Buffer       : ^array [1..1000] of char;
  20.  
  21. Procedure Usage;
  22. begin
  23.     Writeln('Usage: Copier FromName ToName');
  24.     Exit(20);
  25. end;
  26.  
  27. begin
  28.     InputFileName := AllocString(80);
  29.     OutputFileName := AllocString(80);
  30.  
  31.     GetParam(1, InputFileName);
  32.     if InputFileName[0] = Chr(0) then
  33.     Usage;
  34.     GetParam(2, OutputFileName);
  35.     if OutputFileName[0] = Chr(0) then
  36.     Usage;
  37.  
  38.     Infile := DOSOpen(InputFileName, ModeOldFile);
  39.     if Infile <> nil then begin
  40.     Outfile := DOSOpen(OutputFileName, ModeNewFile);
  41.     if Outfile <> nil then begin
  42.         New(Buffer);
  43.         repeat
  44.         Position := DOSRead(Infile, Buffer, 1000);
  45.         if Position > 0 then begin
  46.             Position := DOSWrite(Outfile, Buffer, Position);
  47.             if Position = 0 then begin
  48.             writeln('Write error');
  49.             exit(20);
  50.             end;
  51.         end;
  52.         until Position = 0;
  53.         Dispose(Buffer);
  54.         DOSClose(Outfile);
  55.     end else
  56.         writeln('Could not open output file.');
  57.     DOSClose(Infile);
  58.     end else
  59.     writeln('Could not open input file.');
  60. end.
  61.