home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / win-os2.swg / 0019_Windows File Copy.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-11-26  |  1.4 KB  |  68 lines

  1.  
  2. {
  3. WINDOWS File Copy
  4. Michael Vincze
  5. mav@asd470.dseg.ti.com
  6. }
  7.  
  8. uses
  9.   WinTypes,
  10.   WinProcs,
  11.   Objects;
  12.  
  13. const
  14.   BufStreamSize = $400;
  15.  
  16. var
  17.   InBufStream : TBufStream;
  18.   OutBufStream: TBufStream;
  19.   C           : Byte;
  20.  
  21. procedure Gasp;
  22. var
  23.   Msg: TMsg;
  24. begin
  25. while PeekMessage (Msg, 0, 0, 0, pm_Remove) do
  26.   with Msg do
  27.     if (Message < wm_KeyFirst) or (Message > wm_MouseLast) or
  28.        ((Message > wm_KeyLast) and (Message < wm_MouseFirst)) then
  29.       begin
  30.       TranslateMessage (Msg);
  31.       DispatchMessage (Msg);
  32.       end;
  33. end;
  34.  
  35. { function copies one file to the other.  The return code
  36.   is the same as the TBufStream return codes.  The Gasp
  37.   procedure is inserted to yield for other applications
  38.   during a copy.
  39. }
  40. function MyCopy (InFileName, OutFileName: PChar): Word;
  41. begin
  42. InBufStream.Init (InFileName, stOpenRead, BufStreamSize);
  43. if InBufStream.Status <> stOk then
  44.   begin
  45.   MyCopy := InBufStream.Status;
  46.   end
  47. else
  48.   begin
  49.   OutBufStream.Init (OutFileName, stCreate, BufStreamSize);
  50.   if OutBufStream.Status <> stOk then
  51.     begin
  52.     MyCopy := OutBufStream.Status;
  53.     end
  54.   else
  55.     begin
  56.     InBufStream.Read (C, 1);
  57.     while InBufStream.Status = stOk do
  58.       begin
  59.       Gasp;
  60.       OutBufStream.Write (C, 1);
  61.       InBufStream.Read (C, 1);
  62.       end;
  63.     end;
  64.   end;
  65. InBufStream.Done;
  66. OutBufStream.Done;
  67. end;
  68.