Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Convert a UNIX linefeed delimited text file to a DOS CR/LF delimited file Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
21-Nov-02
Category
Files Operation
Language
Delphi 2.x
Views
186
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I'm having an issue converting a Unix 1.15 GB text file to a Windows file. It 
always seems my application runs out of memory during the conversion. Does anyone 
have any ideas as to how to accomplish this?

Answer:

It sounds like you're trying to read the whole file into memory or something. How 
does this work:

1   program unix2dos;
2   
3   {$APPTYPE CONSOLE}
4   
5   uses
6     SysUtils;
7   
8   var
9     fp1: file;
10    fp2: TextFile;
11    buffer, buf2: array[1..8192] of Char;
12    numread: Integer;
13    i: Integer;
14  begin
15    if paramcount <> 2 then
16    begin
17      writeln('USAGE : UNIX2DOS <input file> <output file>');
18      writeln(' Takes UNIX text file (linefeed delimited) and');
19      writeln(' converts it to a DOS (CR/LF) delimited text file.');
20      halt(10);
21    end;
22    if FileExists(Paramstr(1)) then
23    begin
24      AssignFile(fp1, paramstr(1));
25      Reset(fp1, 1);
26      AssignFile(fp2, paramstr(2));
27      SetTextBuf(fp2, buf2);
28      rewrite(fp2);
29      repeat
30        BlockRead(fp1, buffer, sizeof(buffer), Numread);
31        if Numread <> 0 then
32        begin
33          for i := 1 to Numread do
34          begin
35            if buffer[i] = #10 then
36              writeln(fp2)
37            else
38              write(fp2, buffer[i]);
39          end;
40        end;
41      until
42        NumRead = 0;
43      close(fp1);
44      close(fp2);
45    end
46    else
47      writeln('Could not find file : ', paramstr(1));
48  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC