PC Review


Reply
Thread Tools Rate Thread

Clear the content of a file

 
 
=?Utf-8?B?WGVybw==?=
Guest
Posts: n/a
 
      17th Nov 2004
Hello.
How do you clear the content of a *.txt file?
Thanks.

--
Xero

http://www.chezjeff.net
My personal web portal
 
Reply With Quote
 
 
 
 
Derek Harmon
Guest
Posts: n/a
 
      17th Nov 2004
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this)> wrote in message
news:4370B592-5572-42D4-BAA2-(E-Mail Removed)...
> How do you clear the content of a *.txt file?


System.IO.File.Open( "foo.xml", System.IO.FileMode.Truncate).Close

Bit of an audacious one-liner, but you get the drift. Open the file in truncate
mode, then (as there's nothing really to do in truncate mode after having reset
the file to zero-length) close it.

Opening it with FileMode.Create will also achieve the same thing, and allow
you to use the FileStream afterwards, for instance,

Dim fileStream As System.IO.FileStream
fileStream = System.IO.File.Open( "foo.xml", System.IO.FileMode.Create)
'
' foo.xml is now zero-length, plus use can write to fileStream.
'
fileStream.Flush
fileStream.Close


Derek Harmon


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      17th Nov 2004
Jeff,

Derek gave you the answer, however what he did not write in my opinon in
words was.

"Just create an empty one with the same name". (And than use one of his
samples)

Only meant as addition

Cor

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this)>
> Hello.
> How do you clear the content of a *.txt file?
> Thanks.



 
Reply With Quote
 
=?Utf-8?B?WGVybw==?=
Guest
Posts: n/a
 
      17th Nov 2004
I see.
Thanks very much, guys.

Xero
"Cor Ligthert" wrote:

> Jeff,
>
> Derek gave you the answer, however what he did not write in my opinon in
> words was.
>
> "Just create an empty one with the same name". (And than use one of his
> samples)
>
> Only meant as addition
>
> Cor
>
> "Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this)>
> > Hello.
> > How do you clear the content of a *.txt file?
> > Thanks.

>
>
>

 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      17th Nov 2004
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this)> schrieb:
> How do you clear the content of a *.txt file?


Open the file using 'FileStream' and use its 'SetLength' method to reset the
file's length.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear Content except for Formulas =?Utf-8?B?Rmlsbw==?= Microsoft Excel Programming 2 1st May 2007 12:29 AM
Clear an XML Map of all content DangerMouse Microsoft Excel Programming 1 23rd Jun 2006 02:43 PM
How to clear file content?! =?Utf-8?B?REhhcnJ5?= Microsoft Dot NET 3 30th Apr 2006 02:36 PM
How to CLEAR a field's content (2) ? Martin Microsoft Access 2 5th Jan 2006 06:50 AM
clear up the content but not the file =?Utf-8?B?VGlt?= Microsoft Access External Data 2 15th Sep 2005 08:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:29 PM.