Advertisement

04.24.2008 at 12:50PM PDT, ID: 23351666
[x]
Attachment Details

get all sub directories and files from those directories

Asked by NurveTech in Microsoft Visual C#.Net, .NET, C# Programming Language

Tags: c#

What i am trying to do is get a lst of files in all directories from the specified directory root.

here is my code, but it only returns one directory and then doesnt print the files for the main directory.

  private void getFilesInSubs()
        {
 MyOrionDS.FileInfo.Clear();
            string path = textBox1.Text;

            DirectoryInfo subdirs = new DirectoryInfo(path);
            DirectoryInfo[] dirs = subdirs.GetDirectories("*");
            foreach (DirectoryInfo directory in dirs)
            {
                System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(directory.FullName);
                if (tbxFileType.Text.Length == 0)
                {
                    pattern = "*.*";
                }
                else
                {
                    pattern = "*." + tbxFileType.Text;
                }
                System.IO.FileInfo[] fInfo = dInfo.GetFiles(pattern);
                foreach (System.IO.FileInfo fi in fInfo)
                {
                    //string fileInfoStuff = "";
                    string fileName = fi.FullName;
                    //string fileversion = "";
                    DateTime creationTime = fi.CreationTime;
                    DateTime LastModifyDate = fi.LastWriteTime;
                    System.Diagnostics.FileVersionInfo myFileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(fileName);
                    //MessageBox.Show(myFileVersionInfo.ToString());
                    //fileInfoStuff = fi.Name + " | " + creationTime + " | " + myFileVersionInfo.FileVersion;

                    OrionDataSet.FileInfoRow newFileInfoRow = (OrionDataSet.FileInfoRow)MyOrionDS.FileInfo.NewFileInfoRow();

                    newFileInfoRow.FileName = fi.FullName;
                    newFileInfoRow.LastModifyDate = LastModifyDate;
                    newFileInfoRow.CreateDate = creationTime;
                    newFileInfoRow.VersionNumber = myFileVersionInfo.FileVersion;

                    MyOrionDS.FileInfo.Rows.Add(newFileInfoRow);
                    MyOrionDS.FileInfo.AcceptChanges();



                    //lbxPreview.Items.Add(fileInfoStuff);
                }
            }

            dataGridView1.DataSource = MyOrionDS.FileInfo;
}Start Free Trial
[+][-]04.24.2008 at 12:58PM PDT, ID: 21434567

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.

 
[+][-]04.24.2008 at 01:00PM PDT, ID: 21434594

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.

 
[+][-]04.24.2008 at 01:17PM PDT, ID: 21434732

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, .NET, C# Programming Language
Tags: c#
Sign Up Now!
Solution Provided By: tgerbert
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628