Question

I'm using 2008 and am unable to use the EnumerateFiles class.

Any folder beyond the root level are essentially ignored when attempting to sum the files within listed network path. Here's my code:

    public void getLeverageServer(string Server)
    {
        int Inp = 0;
        int Out = 0;
        int Ex = 0;

        string output = "\\\\" + Server + "\\F\\Output";
        string input = "\\\\" + Server + "\\F\\Input";
        string exceptions = "\\\\" + Server + "\\F\\Exceptions";

        string[] pathIn = Directory.GetFiles(input);
        string[] pathOut = Directory.GetFiles(output);
        string[] pathExceptions = Directory.GetFiles(exceptions);

        foreach (string element in pathIn)
        {
            Inp++;
        }

        foreach (string element in pathOut)
        {
            Out++;
        }

        foreach (string element in pathExceptions)
        {
            Ex++;
        }

        txtLevInp.Text = Convert.ToString(Inp);
        txtLevOut.Text = Convert.ToString(Out);
        txtLevExc.Text = Convert.ToString(Ex);
        txtLevTotal.Text = Convert.ToString(Out + Ex);
    }
Was it helpful?

Solution

You need a different overload of Directory.GetFiles

string[] pathIn = Directory.GetFiles(input, "*.*", SearchOption.AllDirectories);

And you don't need to count the files found. Just read the value of the property Length of the returned array....

txtLevInp.Text = pathIn.Length;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top