Results 1 to 7 of 7

Thread: Over Write a File?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    193

    Over Write a File?

    How would i over write a file?

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Over Write a File?

    Delete it then write to same file name?
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Lively Member zexor's Avatar
    Join Date
    Mar 2010
    Posts
    68

    Re: Over Write a File?

    are you trying to copy a file or write to a file? what are you trying to do?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    193

    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.

  6. #6
    Hyperactive Member The Fire Snake's Avatar
    Join Date
    Sep 2009
    Location
    USA
    Posts
    401

    Re: Over Write a File?

    Quote Originally Posted by NoobieO.o View Post
    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:
    1. Imports System.IO
    2.  
    3. Private Sub MyWriter()
    4.    Try
    5.       Dim PathOfFile As String = "Whatever you want"
    6.       Dim Writer As New StreamWriter(PathOfFile, False)
    7.  
    8.       ' Writing to the file
    9.         Writer.Write("nop")
    10.  
    11.       'Close StreamWriter
    12.        Writer.Close()
    13.        
    14.    Catch a As Exception
    15.       MsgBox("error")
    16.     End Try
    17. End Sub

    Ask if you have any questions!
    Remember to click on the scales to the left and rep me if I helped

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Over Write a File?

    Quote Originally Posted by NoobieO.o View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width