0

以下は、次のことを行うと思われる私のコードです。

  1. XML タグ値を抽出する
  2. 検索パターとして渡す
  3. 一致するパターンを見つける (このファイル名のタグ値に基づく)
  4. 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);

    }
}

コードをコンパイルするとエラーは発生しませんが、期待した結果が得られない理由を理解するのに苦労しています。

4

1 に答える 1

0

いくつかの点が少し奇妙に見えます:

  1. foreach ループ内 (メイン) で 2 つの文字列変数を宣言します。これらは他の場所では参照されません。

  2. FileCopy を呼び出すことはありません。

于 2013-10-05T22:38:34.283 に答える