Article View: borland.public.cppbuilder.nativeapi
Article #17116Re: Split file.
From: Safari
Date: Wed, 09 Apr 2003 18:30
Date: Wed, 09 Apr 2003 18:30
52 lines
2672 bytes
2672 bytes
Hello Remy,
1. I fail to write or complete this code! return me two errors.
{a. Stream read error.
{b. File1: MyFile.001, File2: MyFile.003, File3: MyFile.005 and ...
2. Your simple code dosn't write any file!, excuse me.
Thanks a lot,
Safari
Remy Lebeau (TeamB) wrote:
> Simply read the file in a loop, each iteration of the loop reading a block
> of data and processing it as needed, continuing until the loop has read the
> entire stream in full. For example:
>
> int iSourceFile = FileOpen("C:\\somefile.ext", fmOpenRead |
> fmShareDenyWrite);
> if( iSourceFile == -1 )
> {
> BYTE buffer[50000];
> int iNum = 1;
>
> do
> {
> int iRead = FileRead(iSourceFile, buffer, 50000);
> if( iRead != -1 )
> {
> if( iRead == 0 )
> break; // finished
>
> AnsiString ext = Format("%.3d", ARRAYOFCONST(( iNum++ )));
>
> int iNewFile = FileCreate("c:\\MyFile." + ext);
> if( iNewFile != -1 )
> {
> if( FileWrite(iNewFile, buffer, iRead) != iRead )
> // an error occured, handle it as needed
>
> FileClose(iNewFile);
> }
> else
> // an error occured, handle it as needed
> }
> else
> // an error occured, handle it as needed
> }
> while( true );
> FileClose(iSourceFile);
> }
> else
> // an error occured, handle it as needed
>
> Gambit
Technical Details
Message-ID:
<3E9466BC.8060508@alloymail.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3E8F1D05.40008@alloymail.com> <3e8f69e0@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,8f5102c5a422c5bb X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-04-09 14:17:51 PST Message-ID: <3E9466BC.8060508@alloymail.com> Date: Wed, 09 Apr 2003 23:00:20 +0430 From: Safari <Safari@alloymail.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Split file. References: <3E8F1D05.40008@alloymail.com> <3e8f69e0@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 81.28.33.98 X-Trace: newsgroups.borland.com 1049922895 81.28.33.98 (9 Apr 2003 14:14:55 -0800) Lines: 53 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail