home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / pascal / 8415 < prev    next >
Encoding:
Text File  |  1993-01-21  |  2.2 KB  |  67 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!munnari.oz.au!yarrina.connect.com.au!auspost.com.au!simon
  3. From: simon@guk.auspost.com.au (Simon Carter)
  4. Subject: Re: Fast "COPY" Routine help...PLEASE.
  5. Message-ID: <1993Jan22.000258.3503@auspost.com.au>
  6. Sender: usenet@auspost.com.au (USENET Administrator)
  7. Organization: Australia Post
  8. X-Newsreader: TIN [version 1.1 PL6]
  9. References: <93019.173648SJS132@psuvm.psu.edu>
  10. Date: Fri, 22 Jan 1993 00:02:58 GMT
  11. Lines: 54
  12.  
  13. SJS132@psuvm.psu.edu wrote:
  14. : [Stuff deleted!]
  15.  
  16. {I don't have any Turbo stuff here, so minor detailse may be incorrect}
  17.  
  18. * Firstly, you are opening the OutFile in READONLY mode. Change the
  19. FileMode before rewriting it.
  20.  
  21. * Use a record size of one byte when opening the files. Otherwise,
  22. if the file is not an integral number of records long, the incorrect
  23. number of bytes will be written.
  24.  
  25. * You don't need {$I-} {$I+} around the BlockRead unless you are
  26. performing some error checking. It you include the 4th
  27. variable (BytesGot <- which incidentally should be RecordsGot), no
  28. error is produced if less than the requested number of records
  29. can be read.
  30.  
  31. * Let me suggest the following:
  32.  
  33.  
  34.        Assign(Infile,FileName);       {Assign the File}
  35.        Assign(OutFile,Path);          {Assign the File}
  36.  
  37.        FileMode := 0;      {Open the INFILE as READONLY}
  38.        Reset(Infile,1);    {Open the input}
  39.  
  40.        FileMode := 1;      {Open OUTFILE as WRITEONLY}
  41.        Rewrite(OutFile,1); {Create or clear the output}
  42.  
  43.     repeat
  44.              BlockRead(InFile,BP^,RecSize,BytesGot);
  45.              BlockWrite(OutFile,BP^,BytesGot);
  46.         until (BytesGot < RecSize);
  47.  
  48.         Close(Outfile);
  49.         Close(Infile);
  50.  
  51.  
  52. * If you are writing a copying program (unless it's for you own
  53. exclusive use), you should be checking the value of ParamCount BEFORE
  54. using ParamStr(1) and ParamStr(2). Check they exist before 
  55. blindly using them! 
  56.  
  57.  
  58. Hope this helps,
  59.  
  60. Simon
  61. --
  62. +-----------------------------------------------------------+
  63. | Simon Carter: 3rd Year Elec/Comp Sci, Monash Uni, Clayton |
  64. |   Net: simon@auspost.com.au (currently)          \\|//    |
  65. | /simon% find -greatquotes -print >> .signature   (o o)    |
  66. +-----------------------------------------------ooO-(_)-Ooo-+
  67.