フォルダーからファイルをコピーして、作成した別のフォルダーに貼り付けようとしています
以下のコードでフォルダーを作成済みです。
DirectoryInfo di = Directory.CreateDirectory(path);
path は、フォルダーが作成される場所のパスです。
このフォルダを別のフォルダのファイルで埋めるにはどうすればよいですか pls.
ありがとう
これにより、必要なものが得られます。
これにより、指定された検索パラメーターを持つファイルが検索され、コピーされます。
public static void findAndCopy(string _sourcePath, string _destPath, string _searchParam )
{
if (System.IO.Directory.Exists(_sourcePath))
{
string[] files = System.IO.Directory.GetFiles(_sourcePath, _searchParam, System.IO.SearchOption.AllDirectories);
string destFile = "";
string fileName = "";
// Copy the files
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(_destPath, fileName);
try
{
System.IO.File.Copy(s, destFile, false);
}
catch (UnauthorizedAccessException uae)
{
log.Warn(uae);
}
catch (IOException ioe)
{
log.Warn(ioe);
}
}
}
else
{
log.Error("Source path not found! " + _sourcePath);
}
}//end findAndCopy