下面是我的代码,它应该执行以下操作:
- 提取 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);
}
}
当我编译代码时,它没有给我任何错误,但我很难理解为什么它没有产生预期的结果。