🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #17368

Re: Split file.

#17368
From: Remy Lebeau (TeamB)
Date: Sat, 05 Apr 2003 23:42
52 lines
2512 bytes
"Safari" <Safari@alloymail.com> wrote in message
news:3E8F1D05.40008@alloymail.com...

> How can i split a file with TFileStream?
> I want to read Exmp:
> 1..50,000 bytes of 1,000,000 bytes to MyFile.001
> 50,001..100,000 bytes of 1,000,000 bytes to MyFile.002

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: <3e8f69e0@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!ken-transit.news.telstra.net!news.telstra.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3E8F1D05.40008@alloymail.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-05 15:45:37 PST
From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3E8F1D05.40008@alloymail.com>
Subject: Re: Split file.
Date: Sat, 5 Apr 2003 15:42:38 -0800
Lines: 54
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 207.175.226.26
Message-ID: <3e8f69e0@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1049586144 207.175.226.26 (5 Apr 2003 15:42:24 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!ken-transit.news.telstra.net!news.telstra.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail