[1]重命名、移动文件
C#中没有重命名的方法,用move to。
[2]
// 改名方法
FileInfo fi = new FileInfo(oldStr);
fi.MoveTo(Path.Combine(newStr));
[2]
/// <summary>
/// 重命名文件夹内的所有子文件夹
/// </summary>
/// <param name="directoryName">文件夹名称</param>
/// <param name="newDirectoryName">新子文件夹名称格式字符串</param>
public void RenameDirectories(string directoryName, string newDirectoryName)
{
int i = 1;
string[] sDirectories = Directory.GetDirectories(directoryName);
foreach (string sDirectory in sDirectories)
{
string sDirectoryName = Path.GetFileName(sDirectory);
string sNewDirectoryName = string.Format(newDirectoryName, i++);
string sNewDirectory = Path.Combine(directoryName, sNewDirectoryName);
Directory.Move(sDirectory, sNewDirectory);
}
}