Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   About Adding Text to Beginning of File (http://www.programmingforums.org/showthread.php?t=14002)

pal Sep 20th, 2007 10:23 PM

About Adding Text to Beginning of File
 
I'm trying to add code in the beginning of approximately 3000 files. The codes are going to be the same on every file. However all of the 3000 files contain texts, therefore I need to create a program that loops through all the files and adds the codes just in the beginning of the file.

Do you know the most efficient way to approach this?

ReggaetonKing Sep 20th, 2007 10:39 PM

Take the current text in the file and put it in a string, we'll call it strContents. Take the text you want to insert in the files and save it in another string, calling it strCode;

strNewContents = strCode + "\n" + strContents

^Do something like that and translate it to C++.

DaWei Sep 20th, 2007 11:36 PM

For each file:

Open a temp file. Write the code to be added to the temp file. Open the old file. Read that and write the contents to the temp file. Close both files. Rename the temp file to the name of the old file.

If you have failed to properly describe what you need, then toss out this answer, along with your description.

pal Sep 21st, 2007 12:18 AM

thanks for the tips.
I'll put them to use.


All times are GMT -5. The time now is 3:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC