以下は、次のことを行うと思われる私のコードです。
- XML タグ値を抽出する
- 検索パターとして渡す
- 一致するパターンを見つける (このファイル名のタグ値に基づく)
- C:\MR にコピーします。
コード:
static void Main(string[] args)
{
XmlDocument xml = new XmlDocument();
xml.Load(@"C:\Temp\XML\BBG_20001.xml");
XmlNodeList xnList = xml.SelectNodes("/FileDump/Message/Attachment");
foreach (XmlNode xn in xnList)
{
string FileName = xn["FileName"].InnerText;
string FileID = xn["FileID"].InnerText;
}
}
public void FileCopy(string[] args)
{
string fileName = "";
string sourcePath = @"C:\temp\MR\";
string targetPath = @"C:\MR";
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
string pattern = @"FileName";
var matches = Directory.GetFiles(@"C:\temp\MR\")
.Where(path => Regex.Match(path, pattern).Success);
foreach (string file in matches)
{
Console.WriteLine(file);
fileName = System.IO.Path.GetFileName(file);
Console.WriteLine(fileName);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(file, destFile, true);
}
}
コードをコンパイルするとエラーは発生しませんが、期待した結果が得られない理由を理解するのに苦労しています。