Hi,

This is my second post in continuation to my previous one. How can I loop through all the files in a folder.

Cheers!
Ali

You can use foreach cycle. E.g. like this:

foreach(string fileName f in Directory.GetFiles("SomeDirectory"))
{
    ...
}

Thanks, but it gives me the error that the Directory doesn't exists in the current context.

How can I declare it?

You can use foreach cycle. E.g. like this:

foreach(string fileName f in Directory.GetFiles("SomeDirectory"))
{
    ...
}
commented: using System.IO; +0

You dont.. Its a predefined class in .net - have a check in your helpfile, its clever and tells you what references (if necessary) and what "using" statements you would need

Direcrory class placed in System.IO. So you sould add import to it:

using System.IO;

Thanks, got it. :)

Direcrory class placed in System.IO. So you sould add import to it:

using System.IO;

How can I display a message showing the fileNames retrieved from the given directory.

1.
foreach(string fileName f in Directory.GetFiles("SomeDirectory"))
2.
{
3.
...
4.
}

Direcrory class placed in System.IO. So you sould add import to it:

using System.IO;

Have you looked at what you get in the foreach loop?
OK while that code wont work specifically it has a big raving clue in it...

What do you think the clue is?

When you call GetFiles method, it return to you an array of strings (filenames). To show them in the message, you should organize them in way, that you like into a string. After that you can see here a bit about showing messages: MessageBox Class

Thanks, I'm done for now. Wasn't using right syntax for message box. Thanks for all your help.

c ya tomorrow!!!
Regards,
Ali

When you call GetFiles method, it return to you an array of strings (filenames). To show them in the message, you should organize them in way, that you like into a string. After that you can see here a bit about showing messages: MessageBox Class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.