Solved

Foreach FileInfo in DirectoryInfo

Posted on 2010-08-29
3
1,160 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now