Getting list of folders in location

M

Mike P

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?
 
M

Morten Wennevik [C# MVP]

Mike P said:
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.
 
M

Mike P

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top