Results 1 to 3 of 3

Thread: Skip over if error

  1. #1

    Skip over if error

    Using the Directory.GetDirectories() method I want to get a list of all directories in C:\ but this means it also tries to access hidden system folders such as the recycle bin and throws an error.
    Is there a way to continue the search is the UnauthorizedAccessException is triggered and just skip that directory?
    Thanks.
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  2. #2
    1,806
    posts
    My Pimp Hand is Strong
    Try using

    DirectoryInfo parentdir = new DirectoryInfo("path");
    DirectoryInfo[] subdirs = di.GetDirectories();
    foreach(DirectoryInfo di in subdirs) {
    if(di.Attributes != FileAttributes.Hidden) {
    //do w/e
    }
    }


    something along those lines

  3. #3
    Thanks I'll see if I can do that
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012