Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename a file in C#

Tags:

c#

file

rename

How do I rename a file using C#?

like image 659
Gold Avatar asked Jul 10 '10 11:07

Gold


People also ask

Is it possible to rename any function in C?

You can't rename functions,variables, classes,..... in any programming language. In c, a name presents a pointers to location in the memory and that is static.In addition, even if you was able to change it's name, you will have then to change it's calling in the source code.

What is the use of rename ()?

The rename() function shall change the name of a file. The old argument points to the pathname of the file to be renamed. The new argument points to the new pathname of the file.

How do I rename a file in terminal?

To rename a file in the terminal, move the file with mv from itself to itself with a new name. Here's an example. To rename a file on a computer with a graphical interface, you open a window, find the file you want to rename, click on its name (or right-click and select the option to rename), and then enter a new name.


2 Answers

System.IO.File.Move(oldNameFullPath, newNameFullPath); 
like image 36
Aleksandar Vucetic Avatar answered Sep 20 '22 19:09

Aleksandar Vucetic


Take a look at System.IO.File.Move, "move" the file to a new name.

System.IO.File.Move("oldfilename", "newfilename"); 
like image 154
Chris Taylor Avatar answered Sep 21 '22 19:09

Chris Taylor