先看一段代码
/// <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指文件的原来名称;
newName指文件新的名称;
主要应用的
System.IO.Directory.Move(filepath, Savepath);
System.IO.Directory.Delete(filepath);
这两个方法。
转载于:https://www.cnblogs.com/springyangwc/archive/2011/02/28/1967212.html