vb2005 - how to overwrite an existing file?

  • Thread starter Thread starter spowel4
  • Start date Start date
S

spowel4

I'm new to Visual Basic, so I apologize for basic questions.
Here's the code I've got so far, which works as long as the
destination file doesn't already exist:

If My.Computer.FileSystem.FileExists("c:\test.cd") Then
My.Computer.FileSystem.MoveFile("c:\test.cd", "c:
\test.bak")

How do I get it to overwrite the test.bak file if if already exists?
Presently I'm getting an IO exception error
 
I'm new to Visual Basic, so I apologize for basic questions.
Here's the code I've got so far, which works as long as the
destination file doesn't already exist:

If My.Computer.FileSystem.FileExists("c:\test.cd") Then
My.Computer.FileSystem.MoveFile("c:\test.cd", "c:
\test.bak")

How do I get it to overwrite the test.bak file if if already exists?
Presently I'm getting an IO exception error

The FileSystem.MoveFile method is overloaded and one format supports a
boolean as the third parameter. True means overwrite, False means do
not overwrite.

http://msdn2.microsoft.com/en-us/library/fh3171xd.aspx

PS: I found this in about 10 seconds with a Google Search for
FileSystem.MoveFile and this was the first link returned.
 
Back
Top