Problem while accessing directory.

I am trying to create a treeView of all directorys,subdirs and files,
like an file explorer.(is there allready made ones )

I getting error: "Acces denied" while listing directory of C:\System Volume Information\
(edit:) How i can make this one work so it skips the unreadable directoryes/files

Here is the code:


   private void Form1_Load(object sender, EventArgs e)
        {
            foreach (string dirs in Directory.GetDirectories(@"C:\"))
            {

                TreeNode node = new TreeNode();
                node.Text = dirs;
                treeView1.Nodes.Add(node);
                foreach (string files in Directory.GetFiles(node.Text))
                    {
                   
                            TreeNode subNode = new TreeNode();
                            subNode.Text = files;
                            node.Nodes.Add(subNode);
                     }
                }
            }
        }
    }


Answer this question

Problem while accessing directory.

  • Frank Zehelein

    Thanks alot.
  • ahmedilyas

    Normally, you can't access that folder


    WinXP Pro under FAT32
    1. Click Start, and then click My Computer.
    2. On the Tools menu, click Folder Options.
    3. On the View tab, click Show hidden files and folders.
    4. Clear the Hide protected operating system files (Recommended) check box. Click Yes when you are prompted to confirm the change.
    5. Click OK.
    6. Double-click the System Volume Information folder in the root folder to open it.

    7. Check/Assign Permissions to the user who is using the computer



  • Chuck S

    private void Form1_Load(object sender, System.EventArgs e)

    {

    foreach (string dirs in Directory.GetDirectories(@"C:\"))

    {

    if(dirs != "C:\\System Volume Information")

    {

    TreeNode node = new TreeNode();

    node.Text = dirs;

    treeView1.Nodes.Add(node);

    foreach (string files in Directory.GetFiles(node.Text))

    {

    TreeNode subNode = new TreeNode();

    subNode.Text = files;

    node.Nodes.Add(subNode);

    }

    }

    }

    }



  • nmxnmx

    Any change to make the code to: Directory.GetDirectories skip files where cant acces, so it wouldnt stop the program, and i could get list of files
  • Problem while accessing directory.