473,830 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File manipulation

I was wondering what the best method of updating a file was.

heres my prob, ive got a file with say 1million urls and I want to
take the first 10,000 and store them in memory. I want to 10k of urls
to be taken out an the file to be updated. is there anyway i could
move the beggining of the file?? What would b the most efficient way
of updating the file??

thanks for any help in advanced.
Jul 22 '05 #1
3 1611
Chad wrote:
I was wondering what the best method of updating a file was.

heres my prob, ive got a file with say 1million urls and I want to
take the first 10,000 and store them in memory. I want to 10k of urls
to be taken out an the file to be updated. is there anyway i could
move the beggining of the file?? What would b the most efficient way
of updating the file??

thanks for any help in advanced.


You can always append to a file to update it.
If the file consists of fixed sized records then
you can position to a record and write a new value
to the file (assuming the file has random access).

Read about:
seekp
seekg
fseek
tellp
tellg
ftell

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #2
Chad wrote:
I was wondering what the best method of updating a file was.

heres my prob, ive got a file with say 1million urls and I want to
take the first 10,000 and store them in memory. I want to 10k of urls
to be taken out an the file to be updated. is there anyway i could
move the beggining of the file??
No. You have to copy all the following data back to the beginning. Or
you could somehow mark your first 10,000 urls as removed so you can
just ignore them the next time you read.
What would b the most efficient way of updating the file??


Open a new file and copy all the data you want to stay to that new file.
Then rename the new file so it overwrites the old one. The latter is
usually an atomic operation, which means that if something happens (a
crash e.g.) during your update operation, the user will not get corrupt
data.

Jul 22 '05 #3
Chad wrote:

I was wondering what the best method of updating a file was.

heres my prob, ive got a file with say 1million urls and I want to
take the first 10,000 and store them in memory. I want to 10k of urls
to be taken out an the file to be updated. is there anyway i could
move the beggining of the file?? What would b the most efficient way
of updating the file??

There's not way in standard C++ (nor in most implementations ) to remove
anything from the start or middle of a file. Some systems provide
extensions that let you truncate files, but that's OT here. Your only
way to do this is to copy the file. Load your lines into memory, update
them, write them out to a new file, deal with the next batch or copy the
remaining portion of the original file to the new one.

A performance improvement would be if you had a way to categorized the
URLs, so you could break things up into smaller files.

Brian Rodenborn
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3537
by: Paul Moore | last post by:
Does anyone know of a Python library which handles sound file formats (MP3, Ogg, FLAC are the three I'm nost interested in). I'd like something that can manipulate "metadata" - stuff like artist, title, album tags. I'm not critically interested in format conversion, or playing sound files - I can handle that with other applications. I'm using Windows, and Python 2.3, if it matters (as it might for C extensions). I can manage with just...
7
2054
by: Dennis C. Drumm | last post by:
I would like to be able to update an xml file located on my hosted server from my local computer. The server requires a user name and password to access the web site for writing or updating files. Could someone refer me to a doc that explains this or provide some sample code? Thanks,
1
5813
by: ma740988 | last post by:
Trying to some of my reading on file manipulation (ifstream/ofstream/fstream) into action. So now consider. # include <iostream> # include <fstream> # include <cstring> # include <sstream> bool remove_and_create_if_exists( const std::string& filename
2
3583
by: PFI | last post by:
Hi, I recently installed SQL Server 2005 Enterprise Edition (9.0.1399) and I have problems on queries concerning system file manipulation... For example, when I try to increase the Log File of MSDB database : ALTER DATABASE msdb MODIFY FILE (NAME = 'MSDBLog', SIZE = 50MB)
4
3335
by: magix | last post by:
Dear Guru, I'm not so good in file manipulation, but would like to seek for help here. I have following basic code of command line argument as starting point (the code below output the contents of a file:) #include <fstream> #include <iostream>
1
2077
by: scubber | last post by:
hi, im new (as you're going to painfully aware of in a minute) to programming and was wondering if anyone could help with this little problem: i am trying to read a number of values which are separated by newlines, and then manipulate each number until a number =<0 is observed. is there a way i can use something like fgets() to read the line, then once the manipulation is over, print the result and for the process to be repeated with the...
0
2592
by: L'eau Prosper Research | last post by:
Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases new TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set. L'eau Prosper Market Manipulation Profiling Tools Set is a set of advanced tools that help Serious Traders analyze the market direction, market manipulative behavior and predicting the change of trend.
0
2356
by: L'eau Prosper Research | last post by:
NEW TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set By L'eau Prosper Research Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases new TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set. L'eau Prosper Market Manipulation Profiling Tools Set is a set of
1
2797
by: tourist.tam | last post by:
Hi, I am trying to read a file using a BufferedStream and avoiding at maximum the use of string manipulation. I need now some help understanding on how to use byte array to hold the data and manipulate those. I do understand that I will have to pass any of the array created into strings at the end of the process. But I am missing the intermediate steps. And being just introduced to JAVA, my understanding of processing large plain text...
15
17401
by: pakerly | last post by:
How would i do this, convert a test file to excel? Lets say my text file has fields like this: NUMBER NAME ADDRESS PHONE 11002 Test1 TestAddress1 111-2222 lets say the number field is 10 characters long, there is a space and Name field is 15 characters long, there is a space, address can be 25 characters long, there is a space and phone is 10 characters long I want to...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10771
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10487
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10202
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7745
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6950
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3958
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.