WriteFile, insert data in the middle of the file.

Hello,

What I want to do is to insert data (not overwrite existing data) in the 
middle of a big file. Does WriteFile( ) have this option?

If there's no way to insert data in the middle, I guess I have to read out 
all the data from the insertion point, and append my new data, and write them 
back to the file? Isn't this too inefficient? Anybody knows how OS handles 
this kind of "insert in the middle" scenario?

Thank you, I appreciate your opinion.

wk

0
WK (6)
11/7/2005 8:41:04 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
442 Views

Similar Articles

[PageSpeed] 28

Well you answered your own question. There is no way to write to the middle
of the file without overwriting what's already there.  In other word, you
can't expand a file in the middle.
What most programs do is create a temp file write everything they want to
that, then simply delete the old file and rename the temp file to the
correct filename.

AliR.

"wk" <wk@discussions.microsoft.com> wrote in message
news:95B74BD6-9C73-4150-BFF3-7694D337CA8D@microsoft.com...
> Hello,
>
> What I want to do is to insert data (not overwrite existing data) in the
> middle of a big file. Does WriteFile( ) have this option?
>
> If there's no way to insert data in the middle, I guess I have to read out
> all the data from the insertion point, and append my new data, and write
them
> back to the file? Isn't this too inefficient? Anybody knows how OS handles
> this kind of "insert in the middle" scenario?
>
> Thank you, I appreciate your opinion.
>
> wk
>


0
AliR3470 (3235)
11/7/2005 9:23:27 PM
AliR is right.  Typically you create a temp file, copy up to the point you 
want to insert, insert text, then copy the rest.  You can use this kind of 
function to create a unique temporary file:

CString GetTempFilePath(LPCTSTR strPattern)
{
    CString csPath;
    if(GetTempPath(_MAX_PATH,csPath.GetBuffer(_MAX_PATH+1)) != 0) {
        csPath.ReleaseBuffer();
        CString csTempFile;
        if(GetTempFileName(csPath,strPattern,0,csTempFile.GetBuffer(_MAX_PATH+1)) 
!= 0) {
            csTempFile.ReleaseBuffer();
            return csTempFile;
        }
    }
    return CString();
}

Or you could use a CMemFile or a CString if the file is not really large 
(fits in memory).  For example, open file, read up to point of insert into a 
CString.  Read rest of file into another CString.  Rewind file, write first 
part back to file, write insert part to file, write remaining part to file.

Tom

"wk" <wk@discussions.microsoft.com> wrote in message 
news:95B74BD6-9C73-4150-BFF3-7694D337CA8D@microsoft.com...
> Hello,
>
> What I want to do is to insert data (not overwrite existing data) in the
> middle of a big file. Does WriteFile( ) have this option?
>
> If there's no way to insert data in the middle, I guess I have to read out
> all the data from the insertion point, and append my new data, and write 
> them
> back to the file? Isn't this too inefficient? Anybody knows how OS handles
> this kind of "insert in the middle" scenario?
>
> Thank you, I appreciate your opinion.
>
> wk
> 


0
tserface (3860)
11/8/2005 5:13:54 PM
Reply:

Similar Artilces:

Import Error from 2004 file to '05, 06, Plus, etc
I have a Money 2004 file that works just fine bar the expiration of downloading stock quotes. I previously bought, installed, and tried to use M'05 & M06, but ran into the Cashflow not Updating issue, and figured I just keep using M'04 until I was forced to update. Now, I installed the demo of MPlus and have the same situation, when I import my M04 file, it crashed the program (same as M05 and M06), the import never completes. Money restarts, and it appears all my data is there, but it runs terribly slow, and the cashflow doesn't work. So, I started the whole list of...

RMS error "Invalid Data Return" on Debits
Credit cards process fine, but the debits error with "Invalid Data Return". We have this same issue. Some debit cards return "Invalid Data Returned" consistently, while other debit cards (from the same bank even) work fine. Try other cards... your configuration might be fine. I'm guessing it's a gateway issue. Jon Wolthuis President Ascend Systems Inc "Joe" <anonymous@discussions.microsoft.com> wrote in message news:1f05601c457b1$a50ac1b0$a601280a@phx.gbl... > Credit cards process fine, but the debits error > with "Invalid Data Re...

importing microsoft outlook files
I've changed laptop and need to transfer mail/contacts/calendar/etc from old to new PC. They tell me *.pst is the solution, BUT it will displace (erase) newly recieved email on new PC! HOW DO I IMPORT - INTEGRATE - OLD FILES INTO NEW ONES ( In article <019b01c3464d$47f105f0$a501280a@phx.gbl>, info@rayfoundation.org says... > I've changed laptop and need to transfer > mail/contacts/calendar/etc from old to new PC. They tell > me *.pst is the solution, BUT it will displace (erase) > newly recieved email on new PC! > > HOW DO I IMPORT - INTEGRATE - OLD FI...

using insert with output
Hello there. I have two tables i need to insert table2 to table1. the field: ID (unique identity) on table2 exist already on table1. So i need insert the data to table1 and get new identity for each rows and get table of the new identity vs old identity: for examlple vstable old_iden, new_iden 5 , 12 6, 13 7, 14 I've tried to do it with output but it can't give me the old ID. is there a way to do this without doing it one by one? > I've tried to do it with output but it can't give me the old ID. is there a way to do this without doing it one ...

Inserting Incremental number
Hi there! I have a table of Assessors [TblAssessors] and a field [RegNo] which is filled in later when trainees have successfully passed. This is later used on a Certificate of Registration. As not all trainees will successfully complete, I'd like to create a macro that will assign an incremental [RegNo] on a button's click event on my data entry form "FrmAssessors". Unfortunately, I have inherited this data and [RegNo] is in the format of "QTA00101","QTA00102", etc. The prefix will always be "QTA" and at this stage we do not envisage eve...

Importing Fixed Width data
Hi, I've been extracting information from my company mainframe, and placing fields into a "fixed length record" file, which I then FTP, and import into Excel 2000. Each record contains around 200 fields, and the import process is VERY painful, for two reasons. - many of the fields are single byte, and clicking to set the start/end point of each is a nightmare. - I generally need to put many of my fields into 'Text' format, as much of the data has leading zeros, which need to be retained. Is there a way that I can set up an import 'template', so that I can just...

inserting a worksheet
is there any way of inserting a worksheet that does not have a sheet number on it. would be handy for using in macros. hi no. the sheet number is how excel keeps track of everything. even if you change the name of the sheet to a non-number name, excel still keep the sheet number in the background. but people have aways gotten around this problem with macros. what problems are you having? Regards FSt1 "ysam4440" wrote: > is there any way of inserting a worksheet that does not have a sheet number > on it. would be handy for using in macros. howdy i wan...

how to recover the file which was not saved? #2
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel accidentally closed the word file which i never saved it. how can I recover it? On 11/4/09 5:37 PM, in article 59b7ffcb.-1@webcrossing.caR9absDaxw, "tanboola@officeformac.com" <tanboola@officeformac.com> wrote: > accidentally closed the word file which i never saved it. how can I recover > it? Time Machine is your only option. Sorry. -- Diane If the file was never saved to disk there is nothing to recover. Time Machine doesn't store what existed only in RAM, nor does even the best file...

WriteFile
Hi , I am using WriteFile function for writting some data to harddisk. Is there any limit in size of data it can write. Basically this function is writting imcomplete data. I checked the contents of file. ( Writs encoded data to file then decode the data using Winzip ( MIME data ) no of Bytes are at boundries like : fff, 9fff, ffff ... Any idea why this is hapening ? I'm not sure if there is a limit, or how to find out. Are you checking the parameter that tells the number of bytes written to see if it equals the number of bytes to write? Perhaps you can just keep calling WriteFile...

saving a .txt file
I have created a macro to auto save a query to a .txt file using the OutputTo command. I first save the format settings, but when it auto saves, the formatting seems to change. For instance, it is printing out the headers, and it is adding in dotted rows. Is there a way to remove this extraneous information from the outpu? ...

Application Data
On my old computer with Outlook express I could goto Windows>Application Data and delete stored files to save room on the drive. I cannot find this on XP and using the full outlook. If anyone could help please email the above addy. Thanks in advance Open Windows Explorer and configure it to show you all hidden/system files. (Select Tools | Folder Options | View tab) "Tres" <tres1013@msn.com> wrote in message news:00c001c35009$b93630d0$a001280a@phx.gbl... > On my old computer with Outlook express I could goto > > Windows>Application Data and delete stored...

How can I insert a check box field?
I have not created a form in a long time. It used to be: Insert Form Field/Check box, and THERE it was! ....Now, with Word 2007, I cant figure it out. I've gone into Insert/Quick Parts/Field... and I'm lost after that. Help!!! On Mon, 8 Feb 2010 16:17:01 -0800, DPOOL <DPOOL@discussions.microsoft.com> wrote: >I have not created a form in a long time. It used to be: Insert Form >Field/Check box, and THERE it was! ....Now, with Word 2007, I cant figure it >out. I've gone into Insert/Quick Parts/Field... and I'm lost after that. >Help!!! ...

sorting matrix data
I have a matrix that returns the volume by month of certain items. The months represent the colum data. How do I sort the data that appears in month column "today's month -7"? Please help. See if that helps you http://msdn.microsoft.com/en-us/library/cc627509.aspx "dataGirl" <dataGirl@discussions.microsoft.com> wrote in message news:548C4B6F-84C1-4114-8B29-79B8C53837B1@microsoft.com... >I have a matrix that returns the volume by month of certain items. The > months represent the colum data. How do I sort the data that appears in >...

How to Insert images on Buttons
hello sir, I am new to VC please help me How to Insert bitmap or gif images on Buttons? Thanks Thomsan Take a look at examples in button control section at www.codeguru.com and www.codeproject.com. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "Thomsan" <Thomsan@hotmail.com> wrote in message news:#vYisTqdDHA.2312@TK2MSFTNGP12.phx.gbl... > hello sir, > > > I am new to VC please help me > How to Insert bitmap or gif images on Buttons? > > Thanks > > Thomsan > > ...

Address Book Files
What are the names and extensions for both Outlook and Outlook Express? -- Thank You, Robert Runkel P.O. Box 1816 Monterey, CA 93942-1816 Home Phone: 831-648-8651 Cell Phone: 831-402-4943 FAX Phone: 831-649-7174 Below is the email address to contact Bob Runkel: <mailto:BRUNKEL@ACM.ORG> ...

Problems with sending PDF file attachment
Employee sending emails from home computer running Outlook 10. When she attaches a .pdf file, somehow the mail is duplicated and sent numerous times until she manually shuts down Outlook. Has anyone else experienced this problem. How does it get fixed? Thanks Duffbeerlvr <duffbeerlvr@yahoo.com> wrote: > Employee sending emails from home computer running Outlook 10. When > she attaches a .pdf file, somehow the mail is duplicated and sent > numerous times until she manually shuts down Outlook. Has anyone else > experienced this problem. How does it get fixed? This can be t...

Reversing data in columns
Is there a way you can quickly reverse the order in which data appears in cells of a column in Excel 2000 - I do not want to put the data in alpha/numerical order, simply reverse the order in which the data appears. Florrie In the top adjacent cell, type 1 and fill down to the bottom. You can then sort descending on this column. Andy. "florrie" <anonymous@discussions.microsoft.com> wrote in message news:065901c3c30f$fb8acfd0$a301280a@phx.gbl... > Is there a way you can quickly reverse the order in which > data appears in cells of a column in Excel 2000 - I do not &...

How can I add a footnote or comment to a data point in a chart?
Is it possible to create one's own text for a specific data point in a line chart? (e.g. a word or two that is not in the data table) I can add a note below the chart in a worksheet, but would like something that would stay with the chart itself. Select the series (one click) then select the point (another click). Format menu > Format Selected Point > Data Label. Add a data label to the point using any of the options. Select the data label (two single clicks), then edit the text or type your new text in the formula bar. Bonus: to link the data label to a cell, select the data...

insert running time on excel
Hi, Is there any way to see the current time in excel? cant seem to find an available function in excel. I know that this might require some VBA scripts as I would like to see the seconds "ticking" on a sheet. Any help or suggestions will be appreciated. Thanks function: =NOW() shortcut for non-dynamic entry of current time: CTRL+: (hold CTRL+SHIFT and tap ; key) best wishes -- www.stfx.ca/people/bliengme "hungry burger" wrote: > Hi, > > Is there any way to see the current time in excel? cant seem to find an > available function in excel. > &...

about pst file
This is a multi-part message in MIME format. ------=_NextPart_000_000D_01C54CAB.9859AEA0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable my pst file hasbeen corrupt , can i restore it.if is it posible pls help = me. --=20 Jiwan Jha Luxor Writing Instruments ------=_NextPart_000_000D_01C54CAB.9859AEA0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type...

Inserting yes/no dropdown menu
I want to insert a dropdown menu in a cell so that when the cell is selected, the user can only choose 'yes' or 'no'? I have done this many times but how to do it has totally slipped my mind. Any ideas? Use Data | Validation on the cell and select list - you specify where the list is stored. You will only need 2 cells, containing Yes and No Actually Pete, you can just type Yes,No in the source dialog box. No cells needed. Gord Dibben Excel MVP On 21 Nov 2005 10:57:01 -0800, "Pete" <pashurst@auditel.net> wrote: >Use Data | Validation on the cell a...

Seondary axes line-chart not showing as per data
I have a plotted a periodic 100% stacked column chart with 6 data rows (meaning 6 components of data for each period). I have a secondary periodic data with 5 compenents that I have plotted on secondary axis. Both the data are in per cents. I have equalized the scale on both axes. The problem is that the lines plotted on secondary axes are not plotted in accordance with the values. For example, one data row with values 2% to 6% is appearing near 100% line (100% on both axes are aligned across the same line). Even strange is that when I change the "Series Order" of the same lim...

Converting a formula to data
I hope I can explain this well enough to be understood. I have a LONG column. Each cell in this column contains a formula (=(M331/1000000)+37) which returns a value to the cell. However, when you click on a completed cell, you get the formula in the formula bar. What I would like to do; after I have completed all my data input; is to highlight the cells in this column, and replace the formula with the value in each cell, so that if I want to use this value somewhere else, I copy the value, not the formula. Thanks. -- Howard Hi Howard Just highlight the cells in that ...

How do I group new pivottable data w/old data instead of >5/31/08
I have a pivot table report that shows sales by month. I update it with new data monthly. My problem is that the newest month is showing up under the title heading >5/31/2008 instead of June. All of the other months have the correct monthly title heading. This is annoying. Anybody know what's up? craig ...

How to clean up Stale file in M: drive ?
Encountered the following error while trying to clean up some file in the inbox. >>The file 'pathname with uuencoded filename.eml' could not be opened >>because it does not exist, or is being used by another application. (0x800CCF65, 2) I have ex2k with sp3. Any suggestion ? Leave alone drive M: or you will be sorry. Delete it via Outlook. jj wrote: > Encountered the following error while trying to clean up some file in the > inbox. > > >>>The file 'pathname with uuencoded filename.eml' could not be opened >>>because it does no...