ソースフォルダABCのサブフォルダをコピーしてコピー先のフォルダに貼りたいと思います。しかし、それは動作していません。ここでは私のC#のコードですが、それは正常ですが、サブフォルダだけではなくフォルダ全体をコピーします。asp.netの別のディレクトリにファイルを持つサブフォルダを移動するにはC#
// string fileName = "test.txt";
string sourcePath = "D:\\Shraddha\\Demo_Web_App\\Source";
string targetPath = "D:\\Shraddha\\Demo_Web_App\\Destination";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath);
string destFile = System.IO.Path.Combine(targetPath);
// To copy a folder's contents to a new location:
// Create a new target folder, if necessary.
if (System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
// To copy a file to another location and
// overwrite the destination file if it already exists.
// System.IO.File.Copy(sourceFile, destFile, true);
// To copy all the files in one directory to another directory.
// Get the files in the source folder. (To recursively iterate through
// all subfolders under the current directory, see
// "How to: Iterate Through a Directory Tree.")
// Note: Check for target path was performed previously
// in this code example.
if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
// Copy the files and overwrite destination files if they already exist.
foreach (string s in files)
{
// Use static Path methods to extract only the file name from the path.
//fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath);
System.IO.File.Copy(s, destFile, true);
}
}
else
{
Console.WriteLine("Source path does not exist!");
}
// Keep console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
のディレクトリ構造を維持するためにだから、ファイルはXXの\ソース\で直接あなただけのXX \ソースの下にフォルダとそのコンテンツファイルをコピーしたい、あなたが意味するか\ではなく?そして、それはフォルダ全体をコピーすると、あなたはフォルダのソースのすべての内容を意味するのですか、それともあなたの目的地フォルダの下に新しいフォルダ "ソース"を作成しますか? –
はいサーあなたのコードを進めてください –