|
-
Mar 26th, 2010, 09:40 PM
#1
Thread Starter
Addicted Member
Over Write a File?
How would i over write a file?
-
Mar 26th, 2010, 09:50 PM
#2
Re: Over Write a File?
Delete it then write to same file name?
-
Mar 27th, 2010, 06:34 AM
#3
Re: Over Write a File?
When you open it for writing you either use a method that defaults to overwriting or else specify an argument that forces overwriting. For instance, creating a StreamWriter will default to overwriting an existing file while creating a FileStream requires you to specify whether to overwrite or append.
-
Mar 27th, 2010, 06:51 AM
#4
Lively Member
Re: Over Write a File?
are you trying to copy a file or write to a file? what are you trying to do?
-
Mar 31st, 2010, 04:41 PM
#5
Thread Starter
Addicted Member
Re: Over Write a File?
Oh, Sorry... Im trying do a little project which is a file shredder. Im trying to over write a file with "nop", but i have no clue where to start.
-
Mar 31st, 2010, 05:08 PM
#6
Hyperactive Member
Re: Over Write a File?
 Originally Posted by NoobieO.o
Oh, Sorry... Im trying do a little project which is a file shredder. Im trying to over write a file with "nop", but i have no clue where to start.
So try something like this(put in the path and name of the file for the Path variable like C:\MyFolder\MyFile):
vb Code:
Imports System.IO Private Sub MyWriter() Try Dim PathOfFile As String = "Whatever you want" Dim Writer As New StreamWriter(PathOfFile, False) ' Writing to the file Writer.Write("nop") 'Close StreamWriter Writer.Close() Catch a As Exception MsgBox("error") End Try End Sub
Ask if you have any questions!
Remember to click on the scales to the left and rep me if I helped 
-
Mar 31st, 2010, 06:47 PM
#7
Re: Over Write a File?
 Originally Posted by NoobieO.o
Oh, Sorry... Im trying do a little project which is a file shredder. Im trying to over write a file with "nop", but i have no clue where to start.
I suggest that, in future, you spend a bit more time on your first post and provide a full and clear description from the start. It will save everyone some time.
In theory, you can just open a FileStream and write the same number of Bytes as the file already contains. They could be all 0, all 1 or random values. In practice, I'm not 100% sure that that will actually write to the exact same location on disc as the existing data. You'd have to confirm that. If not then you'd probably have to resort to a low-level API.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|