User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 425,875 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,307 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Jun 4th, 2005
Views: 4,920
This snippet shows how to open, read, write and close text files. This skeleton can be modified to handle any type of file, from untyped to text to typed files.
pascal Syntax | 4 stars
  1. procedure CopyFile;
  2. var
  3. F1 : text;
  4. F2 : text;
  5. FN1 : string;
  6. FN2 : string;
  7. begin
  8. FN1 := 'infile.txt';
  9. FN2 := 'outfile.txt';
  10.  
  11. assign( F1, FN1 );
  12. reset( F1 ); { open file for reading }
  13.  
  14. assign( F2, FN2 );
  15. rewrite( F2 ); { open file for writing, destroying contents, if any }
  16.  
  17. while not EOF( F1 ) do
  18. begin
  19. readln( F1 );
  20. { file manipulation goes here }
  21. writeln( F2 );
  22. end;
  23.  
  24. close( F1 );
  25. close( F2 );
  26. end;
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 6:15 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC