Solved

Foreach FileInfo in DirectoryInfo

Posted on 2010-08-29
3
1,192 Views
Last Modified: 2012-05-10
Hi,

I understood ,  

arr= { 2,4,6,7,2,7,8};
foreach( Int  temp in  arr)    : So this code will iterates with numbers  foreach integer in  arr.
this is true bcoz it is iterating on integets ,but  for this code.

foreach( FileInfo temp in DirectoryInfo )   :    I did not understood this code  

Do directoryinfo contains fileinformation , I am not able to what is the hierarchy.
and the code why it is correct.
Thankyou

Friends Can you please explain  in detail.  
0
Comment
Question by:N_Sri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Accepted Solution

by:
Jini Jose earned 250 total points
ID: 33554338
no directoryinfo contains the directory informations.


here is the sample

DirectoryInfo din = new DirectoryInfo("C:\");
            FileInfo[] fils = din.GetFiles();
            foreach (FileInfo f in fils)
            {
                //do your code
            }
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 250 total points
ID: 33554343
DirectoryInfo would need to be an enumerable source of FileInfo...

*If that is the actual code then it was a very poor choice in naming the variable!

You'd normally see something more like this:

    DirectoryInfo di = new DirectoryInfo(@"c:\some\path");
    foreach(FileInfo fi in di.GetFiles("*.txt"))
    {
        // ... do something with "fi" ...
    }
0
 

Author Closing Comment

by:N_Sri
ID: 33554372
Perfect. Thankyou
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question