0
private int dReturn, fReturn = 0;

public Maker()
{
    InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
    if (fd.ShowDialog() != DialogResult.OK) { return; }
    listView1.Items.Clear();
    dReturn = 0;
    fReturn = 0;
    textBox1.Text = fd.SelectedPath;

    Scanner scanner = new Scanner();

    scanner.Show();
    fscan(fd.SelectedPath);
    dscan(fd.SelectedPath);
    scanner.Close();

    MessageBox.Show("File : " + fReturn + ", Folder : " + dReturn, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private int dscan(string path)
{
    try
    {
        foreach (string d in Directory.GetDirectories(path))
        {
            dReturn = dReturn + 1;
            dscan(d);
            Application.DoEvents();
        }
    }

    catch(Exception)
    {
        ListViewItem access = new ListViewItem(path);
        listView1.Items.Add(access);
    }

    return dReturn;
}

I want know number of folders in selected path. So I made a recursive function as above. But The number of folders not the same as PC property view. Please Help me... Fine when the path is small, the problem arises when large.


Thanks for your comment. Sorry, It was Not enough description. I show you some image.

enter image description here

like this my program search more number of folder.

Hyun
  • 37
  • 8

1 Answers1

3

Maybe you have some hidden folders (C# - Get a list of files excluding those that are hidden) ?

By the way, GetDirectories can return all subdirectories : https://msdn.microsoft.com/fr-fr/library/ms143314(v=vs.110).aspx :

Directory.GetDirectories(path, "*", SearchOption.AllDirectories);

If you still have problems, try debugging to see the differences.

Community
  • 1
  • 1
Bioukh
  • 1,888
  • 1
  • 16
  • 27
  • Thanks for your comment. I add my description. Please confirm once more. sorry i'm bad english – Hyun Jan 27 '16 at 08:21
  • As already said, it could be explained by hidden files and folders or access rights : try launching your application with admin rights to see if it gives a different result. – Bioukh Jan 27 '16 at 08:28
  • Modify your `dscan` function this way : `foreach (string d in Directory.GetDirectories(path).Where(folder => !folder.Attributes.HasFlag(FileAttributes.Hidden)))` and see if the result matches the explorer one. – Bioukh Jan 27 '16 at 08:32
  • I did it. The results came out too small value. Real folders number is 830. And my program search only 32 folders. :( – Hyun Jan 28 '16 at 01:20