【问题标题】:Export instance, ParentNode, Value to chain of events lists将实例、父节点、值导出到事件链列表
【发布时间】:2013-08-06 00:02:13
【问题描述】:

我有一个 powershell 脚本,可以将 Instance、ParentNode 和 Value 导出到我导出到 CSV 文件的列表中。我在多台机器上运行它并将它们附加到主列表中。 示例:

Server1
Instance        ParentNode          Value
----------------------------------------
InstanceA       BatchName           BatchX
InstanceA       SourceFolderPath    \\server\feeds\BlahBlah
InstanceA       DestinationLocation \\Server\archive\BlahBlah
InstanceA       DestinationLocation \\Server\consumption\BlahBlah
InstanceA       BatchName           BatchT
InstanceA       SourceFolderPath    \\server\feeds\i.BlahBlahFailed
InstanceA       DestinationLocation \\Server\archive\i.BlahBlahFailed
InstanceA       DestinationLocation \\Server\consumption\BlahBlahFailed

ServerB
----------------------------------------
InstanceC       BatchName           BatchX
InstanceC       SourceFolderPath    \\Server\archive\i.BlahBlahFailed
InstanceC       DestinationLocation \\Server\archive2\BlahBlah
InstanceC       DestinationLocation \\Server\consumption2\BlahBlah

现在,一些SourceFolderPaths 的目标在其他服务器上的次数增加了 100 次以上。最终目标是能够从头到尾获得一个提要路径列表。任何语言都可以 C#、PHP 等...

【问题讨论】:

  • 假设您只使用 SourceFolderPaths 我已经为您提供了答案。
  • 您想回答的实际问题是什么?

标签: c# list powershell csv


【解决方案1】:

这是解决此问题的一种方法:

        string[] input = File.ReadAllText("textfile3.txt").Split(new string[1] { "SourceFolderPath" }, StringSplitOptions.RemoveEmptyEntries);
        for (int i = 1; i < input.Count(); i++)
        {
            listBox1.Items.Add(input[i].Substring(0,input[i].IndexOf("Instance") - 1).Trim());
        }

如果不希望将整个文件读入内存,您可以像这样遍历文件:

        StreamReader sr = new StreamReader("textfile3.txt");
        while (!sr.EndOfStream)
        {
            string line = sr.ReadLine();
            int index = line.IndexOf("SourceFolderPath");
            if (index >= 0)
            {
                listBox1.Items.Add(line.Substring(index + 16).Trim());
            }
        }

我使用列表框项目集合来存储路径。您也可以轻松地使用 List 来存储它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2017-12-22
    • 2016-10-10
    • 1970-01-01
    相关资源
    最近更新 更多