469,568 Members | 1,435 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

Getting list of folders in location

I need to find all the folders at a certain location, and then once I
have this list of folders I need to add some of them to a collection and
then show the names of those folders on screen (there are certain
folders that I do not want show on screen so I need to be able to have a
foreach loop once I have all the folder names where I can check for
folder names I don't want).

Does anybody know how to do this?
*** Sent via Developersdex http://www.developersdex.com ***
Oct 9 '08 #1
2 1985

"Mike P" wrote:
I need to find all the folders at a certain location, and then once I
have this list of folders I need to add some of them to a collection and
then show the names of those folders on screen (there are certain
folders that I do not want show on screen so I need to be able to have a
foreach loop once I have all the folder names where I can check for
folder names I don't want).

Does anybody know how to do this?
Hi Mike,

The Directory class have methods for retrieving a list of files and folders.
Using an overloaded GetDirectories method you can also specify a filter and
thereby possibly preventing the need for looping through the result.

If you get stuck tell us where and we will help you further.

--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 9 '08 #2
Hi Morten,

I have got to the point where I can return all the folders, but now I
need to remove from that collection the folders that I don't want.
Basically if the folder is called 'additional' or 'notes' then I want to
ignore it. Here is my code so far :

string strPath = Server.MapPath(@"Files\" + FolderName);
DirectoryInfo objCurrentDirectory = new
DirectoryInfo(strPath);
DirectoryInfo[] aryDirectories =
objCurrentDirectory.GetDirectories();

Could I use GetDirectories to screen out these 2 folders if they exist?


*** Sent via Developersdex http://www.developersdex.com ***
Oct 9 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Konrad L. M. Rudolph | last post: by
5 posts views Thread by Krustov | last post: by
6 posts views Thread by Dave Hopper | last post: by
1 post views Thread by Locke Nash Cole | last post: by
2 posts views Thread by laredotornado | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.