移动文件或文件夹:
sourceCode:
string srcFileName = @"D:\a.txt";
string destFileName = @"D:\b.txt";
string srcFolderPath = @"D:\1";
string destFolderPath = @"D:\6";
//方法一
if (System.IO.File.Exists(srcFileName))
{
System.IO.File.Move(srcFileName, destFileName);
}
if (System.IO.Directory.Exists(srcFolderPath))
{
System.IO.Directory.Move(srcFolderPath, destFolderPath);
}
//方法二
if (System.IO.File.Exists(srcFileName))
{
System.IO.FileInfo file = new System.IO.FileInfo(srcFileName);
file.MoveTo(destFileName);
}
if (System.IO.Directory.Exists(srcFolderPath))
{
System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(srcFolderPath);
folder.MoveTo(destFolderPath);
}
本文详细介绍了使用C#语言进行文件与文件夹移动的方法,包括两种实现方式:一是直接使用System.IO.File.Move和System.IO.Directory.Move方法,二是通过FileInfo和DirectoryInfo对象的MoveTo方法来完成移动操作。
2775

被折叠的 条评论
为什么被折叠?



