473,396 Members | 1,936 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,396 software developers and data experts.

File Move URGENT!

If I copy or move a file and the file already exisits how do I overwrite the
old file or rename the new one ?

Thanks in Advance.
Nov 15 '05 #1
2 1852
Check if the file exists first, if it does, delete it and then just
copy/move.
if(File.Exists("DestinationFile"){
File.Delete("DestinationFile");
File.Copy(Source,Destination;
}
HTH,

Bill
"Chris Calhoun" <cc******@medbill.com> wrote in message
news:Ou**************@TK2MSFTNGP12.phx.gbl...
If I copy or move a file and the file already exisits how do I overwrite the old file or rename the new one ?

Thanks in Advance.

Nov 15 '05 #2
IF you are using the System.IO.File.Copy() function, you can pass in a 3rd
parameter (besides the source and destination strings) which is a boolean
value. If this is set to true it will overwrite the destination file. As
for renaming, you would probably have to check for the existance of the file
with code and then go from there.

ex.
using System.IO;
void main()
{
string strSource = "y:\\apath\\afile";
string strTarget = "x:\\apath\\afile";
if ( File.Exists( strTarget ) )
{
strTarget = strTarget + ".new";
}
File.Copy( strSource, strTarget, true );
}
Hope this helps
Carlson Q
"Chris Calhoun" <cc******@medbill.com> wrote in message
news:Ou**************@TK2MSFTNGP12.phx.gbl...
If I copy or move a file and the file already exisits how do I overwrite the old file or rename the new one ?

Thanks in Advance.

Nov 15 '05 #3

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

Similar topics

4
by: Imran | last post by:
Hello All Am trying to read a huge txt file and write to a file back. pls see the code int main() { char* pData;
0
by: Amratash | last post by:
Hi, I needyour help.Its urgent. My main aim is to log the site activities in a database at runtime. I'm using W3C Extended Log File format for logging information. I can use ODBC Logging directly...
0
by: Joey Martin | last post by:
This is urgent, so any quick help is much appreciated!!!! I have an ASP page that pulls data from a SQL table and puts it into a basic html table. This is basic stuff. I moved my pages from a...
10
by: Peter | last post by:
VS 2003 .NET 1.1 What is the fastest way to move 2 dimensional Array of objects into a DataTable, besides using a loop? I have a about 30,000 elements in my array and I have to move it into a...
1
by: kkizer | last post by:
I have a problem with this simple code below. Moving the files works perfectly, but once in a blue moon the file that it is trying to move dissapears before it can move it. and when this happens...
2
by: Gerhard | last post by:
I have a .net application that I want to run in a DMZ, with the SQL Server and file system behind another firewall. Is there a secure way to get to files from my application, or would it be better...
4
by: camarkco | last post by:
Why does C# go out of it's way to prevent this? Mark
3
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
Note: My apologies for repeating this post from last week, but my nospam alias and profile account were incorrect. I think I have fixed this, so hopefully this post will trigger MS into a response...
2
by: deepakthegeek | last post by:
Hi, I have a folder which contains about 25 files, pdf files(25 files) as well as text files (25 files) with the same name but with .pdf and .txt extensions. These text files are actually OCR...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.