Look at the piece of code
/// <summary>
///
/// </summary>
/// <param name="oldName"></param>
/// <param name="newName"></param>
/// <returns></returns>
private bool RenameFilea(string oldName, string newName)
{
string filepath = System.IO.Directory.GetCurrentDirectory() + "\\" + oldName ;
if (System.IO.Directory.Exists(filepath))
{
try
{
string Savepath = System.IO.Directory.GetCurrentDirectory() + "\\" + newName ;
System.IO.Directory.Move(filepath, Savepath);
System.IO.Directory.Delete(filepath);
return true;
}
catch
{
return false;
}
}
else
{
return false;
}
}
olderName refers to the original name of the file;
newName refers to the new name of the file;
The main application of
System.IO.Directory.Move(filepath, Savepath);
System.IO.Directory.Delete(filepath);
These two methods.
Reproduced in: https: //www.cnblogs.com/springyangwc/archive/2011/02/28/1967212.html