Advertisement

05.20.2008 at 12:41PM PDT, ID: 23418589
[x]
Attachment Details

recursively search directories for files

Asked by gladstonesheeba in Microsoft Visual C#.Net, C# Programming Language, Programming for ASP.NET

Tags: microsoft, dotnet, 2008, C#

hi , i just find this code in a website. One thing  i need your help. how to create a datatable with all the file information inside the foreach and display the information in the Gridview. Hope you understood what iam trying to say. search directories for doc files and display those file informatin in the Gridview

namespace Recursion
{
    class IterateFolders
    {
       
        public    static void Main(string[] args)
        {
            //Create a Directory object using DirectoryInfo
            DirectoryInfo dir =
               new DirectoryInfo(@"C:\Program Files\Adobe\Acrobat 5.0");
            //Pass the Directory for displaying the contents
            getDirsFiles(dir);

        }

        //this is the recursive function
        public static void getDirsFiles(DirectoryInfo d)
        {
            //create an array of files using FileInfo object
            FileInfo [] files;
            //get all files for the current directory
            files = d.GetFiles("*.*");

            //iterate through the directory and print the files
            foreach (FileInfo file in files)
            {
                //get details of each file using file object
                String fileName = file.FullName;
                String fileSize = file.Length.ToString();
                String fileExtension =file.Extension;
                String fileCreated = file.LastWriteTime.ToString();

                io.WriteLine(fileName + " " + fileSize +
                   " " + fileExtension + " " + fileCreated);
            }
           
            //get sub-folders for the current directory
            DirectoryInfo [] dirs = d.GetDirectories("*.*");
           
            //This is the code that calls
            //the getDirsFiles (calls itself recursively)
            //This is also the stopping point
            //(End Condition) for this recursion function
            //as it loops through until
            //reaches the child folder and then stops.
            foreach (DirectoryInfo dir in dirs)
            {
                io.WriteLine("--------->> {0} ", dir.Name);
                getDirsFiles(dir);
            }
           
        }

    }
}
Start Free Trial
[+][-]05.20.2008 at 12:59PM PDT, ID: 21609795

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 01:15PM PDT, ID: 21609935

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 01:38PM PDT, ID: 21610125

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 10:49AM PDT, ID: 21626000

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.27.2008 at 06:43AM PDT, ID: 21651762

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.27.2008 at 11:29AM PDT, ID: 21654340

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.27.2008 at 11:36AM PDT, ID: 21654398

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.27.2008 at 01:53PM PDT, ID: 21655599

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.27.2008 at 02:02PM PDT, ID: 21655667

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, C# Programming Language, Programming for ASP.NET
Tags: microsoft, dotnet, 2008, C#
Sign Up Now!
Solution Provided By: topdog770
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628