Question list all folders / files of a Hard drive

zarggin

New member
Joined
Jan 2, 2012
Messages
1
Programming Experience
1-3
Hello ,

I would like to list all files of a partition such as "C: \" and put them on a listbox , I tried but it didn't work ... i said that maybe it was because of the privileges , here's a snapshot containing the code, the form and the error:

http://i.imgur.com/yGCt9.jpg

Thank you in advance for your help
smile.gif
, and sorry for my bad English .
 
Instead of uploading a screenshot to some other site, try putting all the relevant information into your post. If you need to provide an image, which you don't in this case because the form is pretty much irrelevant, attach it to your post directly. For code, put all and only the relevant code into your post wrapped in
 tags for readability.  If there's an error message, just copy it into your post.  That way we can see everything right here, without having to open additional windows or navigate anywhere, and we can copy and paste text if required.  Do as much as you can to make it as easy as possible for us to help you.

Anyway, that exception is unavoidable when traversing the folder tree of an entire drive.  There is always going to be at least one folder that is inaccessible, so you just have to allow for that in your code.  That means not using the AllDirectories option if there is any chance of encountering such a folder.  You need to use the TopDirectoryOnly option and provide your own recursive method.  You can then wrap each individual folder access inside an exception handler instead of the entire search.  That way, when an inaccessible folder is found, you can just ignore the exception that is thrown and move on to continue searching.
 
Back
Top