473,973 Members | 60,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to "Archive" a text file with multiple handles open

Problem: I'd like to archive off the contents of a text file. However,
other processes may have the file open, so MoveTo(newfilep ath) can't be
done, as far as I've found.

Start with a 5 MB MyLog.txt file that may be opened (reading and/or
writing) by several handles. The Final state I'm looking for is an
archive file MyLog_YYYYMMDDH HMMSS.txt with the 5 MB contents and the
original file zeroed out or with a line indicating the archive
operation.

I'm looking for a way to use CopyTo(NewFileP ath) and then "zero out"
the original file....

problem is, I've found no real discussions regarding DELETING text in a
previously established file. How can you use a binarywriter or similar
class to REMOVE bytes or add null bytes. I end up with a file of the
original length.

you can't use the traditional FileInfo instantiation with the Truncate
parameter, as this causes an access violation.

Any ideas?

Jun 16 '06 #1
1 1773
Hello dw*****@gmail.c om,

The design is a little flawed. My first question is.. do you own all the
file handles? If so you may wish to create a single point of writing/reading
which could then easily have the archive code added to it. I use a similar
method for writing to multiple log locations.

While there are open file handles you can't "zero out" (erase the contents
of) a file. The reason being that the other file streams are looking for
data at a particular location.. if you erase the file.. these other streams
have no way of knowing this and can not reset the location they are looking
to read/write.

-Boo
Problem: I'd like to archive off the contents of a text file.
However, other processes may have the file open, so
MoveTo(newfilep ath) can't be done, as far as I've found.

Start with a 5 MB MyLog.txt file that may be opened (reading and/or
writing) by several handles. The Final state I'm looking for is an
archive file MyLog_YYYYMMDDH HMMSS.txt with the 5 MB contents and the
original file zeroed out or with a line indicating the archive
operation.

I'm looking for a way to use CopyTo(NewFileP ath) and then "zero out"
the original file....

problem is, I've found no real discussions regarding DELETING text in
a previously established file. How can you use a binarywriter or
similar class to REMOVE bytes or add null bytes. I end up with a file
of the original length.

you can't use the traditional FileInfo instantiation with the Truncate
parameter, as this causes an access violation.

Any ideas?

Jun 16 '06 #2

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

Similar topics

3
5658
by: Ben Kial | last post by:
I need to write a program to "copy" files and preserved the files' atime, mtime, ctime, file permissions. I also need to have this program working in Unix and Windows, where the "Archive" attribute on the file also has to be preserved (any more Windows idiosyncrasies?). Any help will be very much appreciated. Thanks in advance. Ben
2
6345
by: dmiller23462 | last post by:
Hey guys, I'm back again....I've got the results displaying that I wanted but instead of having a "next" or "previous" link displayed I am getting the error msg below (I actually get the data that I'm supposed to get meaning that my query seems to be working fine but instead of making its way to the INCLUDE file (bottom navigation bar) it displays the following error msg instead of the included nav bar... *** error '80020009' Exception...
4
2332
by: jr | last post by:
I am working in VC++ so this may be microsoft specific though I don't think so. Excuse me if it is. Assuming it isn't, can someone generally explain the purpose of having both - is it purely a deployment/distribution thing. I notice that the static library generates obj files and a Lib file. Could someone kindly explain how they relate to one another. Thanks very much
0
1105
by: Michael | last post by:
After trying to load my java applet from <OBJECT> tag (rather than <APPLET> tag), it renders fine, except when you click between the DESIGN view then back to HTML view, the <PARAM NAME="ARCHIVE" VALUE="jars/myapp.jar"> line completely vanishes. Click to HTML view again, and the applet just does not load or work (as would be expected!). Re-add the vanishing line and all is well again.
3
4429
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here really understand how this could be an issue. The assemblies that the system is complaining about are ones that we build here and we're not changing version numbers on anything. The errors come and go with no apparent rhyme or reason. We do not...
2
2527
by: Danny Boy | last post by:
Hi, "Snif" is an excellent little script to index files and directories. It's just one single file, and the advantage is that you merely drop it into the directory you want to index, point a browser to the script and you're done. But to me, the simplicity is a DISadvantage since I need to index directories that are located down in the site hierarcy, and to which the users won't have direct access.
5
28266
by: balakrishnan.dinesh | last post by:
hi Frnds, I need Confirm box with "yes" or "no" buttons, Is that possible in JAVASCRIPT , Can anyone tell me the solution for this or anyother way to create confirm box with "yes" or "no" button? Thanks & Rgrds Dinesh...
5
1195
by: rdsandy | last post by:
Hi, Im using Access 2003 and SQL Server 2005. I made a stored procedure to do an archiving process, which if theres a change in a certain field, it inserts the certain fields in that row to an "archive" table. The stroed procedure is below: alter PROCEDURE . @RiskID int AS BEGIN
1
3842
by: akansha1234 | last post by:
Hi all, I am facing this problem. When i am building my workspace in eclipse i am getting following exception its very urgent.. 0000004c SystemErr R *** ERROR ***: Fri Sep 12 03:53:38 CDT 2008 com.ibm.etools.j2ee.commonarchivecore.exception.OpenFailureException: IWAE0034E Could not open the nested archive "\WEB-INF\lib" in "cmpdepm.war" at...
0
10160
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,...
1
11560
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10901
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...
0
10071
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8453
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
7600
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();...
0
6542
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4726
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3755
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.