473,471 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Deleting data in binary files

AaronL
99 New Member
Ugh, I suck at programming. Forgive me if this topic was covered before but I couldn't find it. I can't figure out the formula for deleting data in binary files. I understand that you should remove the data in question and then move the rest of the data back where the old data used to be, but how can I do this without choking the cpu? This is currently what is in my head, but I know that my cpu will hate this, if it would even work.
Expand|Select|Wrap|Line Numbers
  1. ReDim LASTFILE(1 to LOF(1) - RECLEN) As Byte
  2. ReDim FILEIN (1 to LOF(1)) as Byte
  3. Get #1,,FILEIN
  4. LASTFILE = FILEIN
  5. For DELLOOP = RECPOS + RECLEN To LOF(1)
  6.      LASTFILE(RECPOS) = FILEIN(DELLOOP)
  7.      RECPOS = RECPOS + 1
  8. Next DELLOOP
That is a horrible code I know, how can I do it right?
Jun 30 '07 #1
1 2322
Killer42
8,435 Recognized Expert Expert
Hi there chelf.

Don't be so hard on yourself. You might be amazed at the number of people who come to places like this and simply post something like "PLZ Gimme The Code To Make An Accounting System With All The Bells And Whistles".

It's refreshing to see someone who's actually attempting their own code, but not too proud to ask for help. :)

I don't really have time to play with the code right now (plus I've never been very good with binary arrays, tending to use strings instead) but in concept, I'd say you're roughly on the right track. One thing to keep in mind. You don't necessarily have to write the entire file back in one go. There are other options.

For starters, just for convenience let's refer to the file as three parts. {A} is the part before where you want to delete some stuff. {B} is the part you want to delete, and {C} is the part after that. One fairly simple and efficient method would be...
  • Read {A} into one array (or string).
  • Read {C} into another array (or string).
  • Write {A} to a new file.
  • Append {C} to the new file.
This may be the fastest way, since it involves reading and writing, once only, just the data to be kept, and never even accessing the unwanted part.

Another thing to think about. It is actually possible to truncate a file (I don't remember how, though). So in theory, you should be able to simply write {C} over the top of {B}, then chop off the redundant data at the end of the file. This would be faster, but more risky.
Jul 1 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
2
by: Stuart Norris | last post by:
Dear Readers, I am developing an application that stores "messages" in array list and writes new entries to a disk file at the end. This file is used incase the user choses to restart the...
6
by: Martin Bischoff | last post by:
Hi, I'm creating temporary directories in my web app (e.g. ~/data/temp/temp123) to allow users to upload files. When I later delete these directories (from the code behind), the application...
8
by: shandra | last post by:
I have a file I need to delete or truncate. I tried using the KILL command in VB6. I tried using the file.delete command in VB.net. I tried manually deleting, renaming, and copying over the...
0
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the...
11
by: E.T. Grey | last post by:
Hi, I have an interesting problem. I have a (LARGE) set of historical data that I want to keep on a central server, as several separate files. I want a client process to be able to request the...
3
by: David Warner | last post by:
Greetings! I am working on a C app that needs to read print files generated by lp that contain HP LaserJet PCL codes. If the PCL contains binary data to define a bit map to be printed on the...
62
by: ivan.leben | last post by:
How can I really delete a preloaded image from memory/disk cache? Let's say I preload an image by creating an Image object and setting its src attribute to desired URL: var img = new Image();...
3
by: showson1 | last post by:
Hi all. We have some files that are basically TIF images with a text header. The header portion is blocked by {startdb} and {enddb}.. it is the same format for all the files. What I need to do...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
1
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...
0
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...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.