473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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(newfilepath) 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_YYYYMMDDHHMMSS.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(NewFilePath) 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 1733
Hello dw*****@gmail.com,

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(newfilepath) 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_YYYYMMDDHHMMSS.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(NewFilePath) 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
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"...
2
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...
4
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...
0
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"...
3
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...
2
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...
5
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?...
5
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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,...

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.