473,406 Members | 2,439 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,406 software developers and data experts.

vb2005 - how to overwrite an existing file?

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

Mar 15 '07 #1
2 9886
On Mar 15, 4:18 pm, "spowel4" <spow...@gmail.comwrote:
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.

Mar 15 '07 #2
On Mar 15, 4:45 pm, z...@construction-imaging.com wrote:
On Mar 15, 4:18 pm, "spowel4" <spow...@gmail.comwrote:
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.
Thank you for the assistance, that worked nicely. I'll try to
remember to use Google more often.

Mar 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gord | last post by:
Hello, If you set the flag for an overwrite prompt using the 'Save' common dialog, how do you read the response when the user clicks the Yes or No in the 'overwrite' message box? Everything...
5
by: Christine Nguyen | last post by:
I've written a program in VB.net. I need to open a file in binary mode and edit it. I cannot find a way to partially overwrite existing data. There are certain hex values I need to replace in the...
1
by: Bernhard Hidding | last post by:
Hello, my program writes an array into a file using the following code: ofstream arrayfile; arrayfile.open("array_file.dat"); .... arraydatei.close(); This works as long as the file does...
3
by: John Smith | last post by:
I would like to write over a file if it exists (or create one if it doesn't exist). The following codes do nothing if the file already exists. How do I get it to overwrite an existing file? ...
8
by: phobos7 | last post by:
I am trying to create a single .EXE that will upgrade a product by the doing the following: 1) Detect the location of the current installation (DONE) 2) Upgrade the existing config file (DONE)...
2
by: B-Dog | last post by:
Is there a way to make vb.net to overwrite the file when moving? Here is what I'm trying to do: If System.IO.File.Exists(dest) Then 'handle overwrite here If MessageBox.Show("Do you want...
1
by: ma740988 | last post by:
Trying to some of my reading on file manipulation (ifstream/ofstream/fstream) into action. So now consider. # include <iostream> # include <fstream> # include <cstring> # include <sstream> ...
7
madhoriya22
by: madhoriya22 | last post by:
Hi, I am getting the data from the CSV file and inserting it to the database. Now while inserting I have to check that some of the data(to be inserted) is already existing in the table or not. If...
1
by: Vae07 | last post by:
Ok so here is a brief summary of my problem. I need a pop up form that submits input text box information to a pocket excel workbook upon a command botton click. Text box inputs are checked for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.