Loop through sub-directories

Hi,
I want to loop through the sub-directories of one given folder. How to correct the following problems?

            dir = args[0];
            ...
            try
            {

                string [] dirlvl2Ent = Directory.GetDirectories(dir);
                for (string dirlvl2 in dirlvl2Ent)
                {

                }

Error	1	; expected	F:\App8\Program.cs	50	37	ProcessSWFile
Error	2	; expected	F:\App8\Program.cs	50	40	ProcessSWFile
Error	3	Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement	F:\App8\Program.cs	50	40	ProcessSWFile

Open in new window

LVL 12
HuaMin ChenProblem resolverAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
Please provide the method that encompasses line 50.

-saige-
0
HuaMin ChenProblem resolverAuthor Commented:
Many thanks.
I now only get the following problem
            try
            {

                string [] dirlvl2Ent = Directory.GetDirectories(dir,"*",SearchOption.AllDirectories);
                for (string dirlvl2 in dirlvl2Ent)
                {

                }
                ...
Error	1	; expected	F:\App8\Program.cs	51	37	ProcessSWFile
Error	2	; expected	F:\App8\Program.cs	51	40	ProcessSWFile

Open in new window

and "for ..." line is line 51.
0
it_saigeDeveloperCommented:
You need to use foreach:
            try
            {

                string [] dirlvl2Ent = Directory.GetDirectories(dir,"*",SearchOption.AllDirectories);
                foreach (string dirlvl2 in dirlvl2Ent)
                {

                }

Open in new window

-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Éric MoreauSenior .Net ConsultantCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.