0
この構造に従います。ディレクトリが空であっても、ディレクトリをソースから宛先にコピーする方法はありますか?
A
A1
A111
A2
A3
A4
B
私の送信元アドレスは次のとおりです。E:\ A \ A2
私の宛先アドレスはEです:\のB
A2が空になったところ私はBにA2をコピーします。
私はこのコードコード
public void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
string vSourceDirName = dir.Name;
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
DirectoryInfo[] dirs = dir.GetDirectories();
// If the destination directory doesn't exist, create it.
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, false);
}
// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName,vSourceDirName,subdir.Name);
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
を使用している場合は、私はC#で、この空のフォルダをコピーすることができますどのようにMSDN からである
BLOCKQUOTE
空であればA2をコピーするのは何ですか? – Kypaz
私は彼がdirが空であってもパスを構築したいと思うと思います。 –
コードはすでにそれを処理しています。何が問題なのですか?どのように調査しましたか? – Luaan