2024年3月13日发(作者:)
C# 如何:复制目录
using System;
using ;
class DirectoryCopyExample
{
static void Main()
{
// Copy from the current directory, include subdirectories.
DirectoryCopy(".", @".temp", true);
}
private static void DirectoryCopy(string sourceDirName, string destDirName, bool
copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = ectories();
if (!)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
// If the destination directory doesn't exist, create it.
if (!(destDirName))
{
Directory(destDirName);
}
// Get the files in the directory and copy them to the new location.
FileInfo[] files = es();
foreach (FileInfo file in files)
{
string temppath = e(destDirName, );
(temppath, false);
}
// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
DirectoryCopy(me, temppath, copySubDirs);
}
}
}
}
string temppath = e(destDirName, );


发布评论