Solved

Foreach FileInfo in DirectoryInfo

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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