Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 20th, 2007, 9:23 PM   #1
pal
Programmer
 
pal's Avatar
 
Join Date: Mar 2005
Location: Washington
Posts: 89
Rep Power: 4 pal is on a distinguished road
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?
pal is offline   Reply With Quote
Old Sep 20th, 2007, 9:39 PM   #2
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
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++.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Sep 20th, 2007, 10:36 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 20th, 2007, 11:18 PM   #4
pal
Programmer
 
pal's Avatar
 
Join Date: Mar 2005
Location: Washington
Posts: 89
Rep Power: 4 pal is on a distinguished road
thanks for the tips.
I'll put them to use.
pal is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding more info to a text file without erasing crawforddavid2006 C# 2 Apr 11th, 2007 2:10 PM
converting string to float beginnerCCC C 22 Oct 2nd, 2006 11:59 PM
OnlineTextEditor.Com! Sane Show Off Your Open Source Projects 43 Jun 16th, 2006 8:55 AM
After execution - Error cannot locate /Skin File? wchar Visual Basic 1 Mar 5th, 2005 9:04 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:39 AM.

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