无法弄清楚为什么 GetFiles(...) 对我不起作用

Can't figure out why GetFiles(...) isn't working for me

我正在制作一个简单的程序,试图通读文本文件并计算特定短语的出现次数。这些文本文件实际上是我服务器的日志文件,但无论如何,包括我的程序在内的文件夹结构就像

FailedReqLogFiles
    ....
LogFiles
    folder1
         textFile1
         textFile2
    folder2
         textFile3
    folder3
         textFile4
         textFile5
         textFile6
wmsvg
    ....
MyProgram.exe 

我 运行

C:\inetpub\logs\MyProgram.exe "LogFiles" "somephrase"

来自 Windows 命令行。我的程序的完整源代码是

using System;
using System.IO;
using System.Text.RegularExpressions;


class Test
{
    static void Main(string[] args)
    {
    // args[1] = expression to search for, e.g. "cloudrealized-email-top-banner"
        try
        {
            int count = 0;
            string [] folders = System.IO.Directory.GetFiles(args[0]); // LogFiles subfolders, e.g. {"W3SVC1", "W3SVC3", "W3SVC5" , ... }
            Console.Write("length of folder: {0}\n", folders.Length);
            foreach (string thisfolder in folders)
            {
                string[] logs = System.IO.Directory.GetFiles(thisfolder);
                foreach (string thislog in logs)
                {
                    using (StreamReader sr = new StreamReader(args[0]))
                    {
                        String line = sr.ReadToEnd();
                        for (Match m = Regex.Match(line, args[1]); m.Success; m = m.NextMatch()) ++count;
                    }
                }
            }
            Console.WriteLine("{0} currences of {1} found in log files", count, args[1]);
        }
        catch (Exception e)
        {
            Console.WriteLine("Error occured");
            Console.WriteLine(e.Message);
        }
    }
}

我不明白为什么找不到文件,因为它一直在打印 "length of folder: 0"

我的程序有什么明显的问题吗?

您正在调用字符串 [] 文件夹 = System.IO.Directory.GetFiles(args[0]);

你试过 Directory.GetDirectories 了吗?

https://msdn.microsoft.com/en-us/library/c1sez4sc(v=vs.110).aspx