private void CopyFolders(string sourceFilePath, string destinationFilePath)
{
try
{
DirectoryInfo startDir = new DirectoryInfo(sourceFilePath);
DirectoryInfo endDir = new DirectoryInfo(destinationFilePath);
if (!endDir.Exists)
{
Directory.CreateDirectory(destinationFilePath);
}
foreach (var item in startDir.GetFiles())
{
File.Copy(item.FullName, endDir + "\\" + item.Name);
}
///递归调用///
foreach (var item in startDir.GetDirectories())
{
string new_sourcefilepath = item.FullName;
string new_destinationfilepath = destinationFilePath + "\\" + item.Name;
CopyFolders(new_sourcefilepath, new_destinationfilepath);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
C#复制文件夹
最新推荐文章于 2024-07-03 09:23:48 发布