我想将一个目录复制到另一个路径。
我找到了这种方法,但它并不会复制目录,只会复制其中的子目录和文件:
string sourcedirectory = Environment.ExpandEnvironmentVariables("%AppData%\\Program");
foreach (string dirPath in Directory.GetDirectories(sourcedirectory, "*", SearchOption.AllDirectories))
{
Directory.CreateDirectory(dirPath.Replace(sourcedirectory, folderDialog.SelectedPath));
}
foreach (string newPath in Directory.GetFiles(sourcedirectory, "*.*", SearchOption.AllDirectories))
{
File.Copy(newPath, newPath.Replace(sourcedirectory, folderDialog.SelectedPath), true);
}
我该如何在输出中获取“Program”文件夹及其所有文件和子文件夹?
结果:
我怎样才能在输出中获得“Program”文件夹及其包含的所有文件和子文件夹?
string.Replace()
或其他路径操作,但这里的代码看起来足够合理)。 - Peter DunihonewPath
,而是folderDialog.SelectedPath
。 - Peter Duniho