Consider a scenario like this
Root
|—–a
|—–b (current folder)
|—–c
|—–etc…
- The current folder is b
- We need to find all folders on the same level as b.
- In other words, What’s the best method to get ‘a‘ and ‘c‘ ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would follow steps similar to @jstarek, but I would drop the second one.
Get the full path to folder b, strip out folder b from the path, list the directories in that path, and exclude folder b from the resulting set.
If you want information more specific to a programming language, please cite which one you are using. You mentioned WinForms so I would guess it’s going to be .Net? If so, the .Net framework already has classes designed to complete this task.
EDIT:
If you’re using .Net take a look at the DirectoryInfo class. It has a GetDirectories method that allows you to list the directories underneath a given directory very easily. It also has overloads for searching etc.
When I have used this in the past, exceptions can be thrown if the user running the program does not have permissions on the folder in question.
Here is a link to a sample of the DirectoryInfo GetDirectory method: http://msdn.microsoft.com/en-us/library/s7xk2b58.aspx#Y798