Rename and Replace file

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am moving file from a folder A to folder B using:

System.IO.File.Move(path, newpath)

I am not sure if this is the best way to do this but I also need to:

1. Rename the file before coping it (I want to keep the extension. I
just want to rename the filename)

2. If the file already exists in the new path I want it to be
replaced.

How can I do this?

Thanks,

Miguel
 
You can use the FileInfo.MoveTo() method. This method moves a specified file
to a new location, providing the option to specify a new file name.
 
Back
Top