How to list *.avi files with whole path in all drives from remote system into an array

searchsanjaysharma
searchsanjaysharma used Ask the Experts™
on
I want to store all avi files in array with all drive/directory/path information in C#
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This is how it can be done in VB.Net, hopefully you can convert to C#
'declare and instantiate directoryinfo
dim DI as new IO.directoryinfo(your path)
'loop through all files with extension of .avi
for each FI sa io.fileinfo in DI.GetFiles("*.avi", all levels option that I can't remember but intellisense should show)
'add path to array
add FI.FullName(?) to your array
next

Commented:
I ported the given code of UnifiedIS to c# - added a little stuff.
Maybe you want to return a List<string> more likely than an array, but that is up to you.
Just call GetMyAvis(initialDirectory);

If this is the solution you searched for please regard UnifiedIS, too, due to the fact that I just ported the code mainly unchanged.
private string[] GetMyAvis(string intial_directory)
        {
            List<string> allAvis = new List<string>();
            System.IO.DirectoryInfo directoryInfo = new DirectoryInfo(intial_directory);
            foreach (FileInfo fileInfo in directoryInfo.GetFiles("*.avi", SearchOption.AllDirectories))            
                allAvis.Add(fileInfo.FullName);            
            return allAvis.ToArray();        
        }

Open in new window

Author

Commented:
The following code i have written in which i am able to view all the drives and the files in the current directory.
Now what i want is :
1. To connect to remote computer.
2. To list the directory contents of all subdirectories.
3. This  logic reads all the drives including detachable drives also. And raises an error. Kindly help.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        public static void Main()
        {
           
            DirectoryInfo dir;
            FileInfo[] files;
           
            for (int i = 0; i < getdrives().Count; i++)
            {
                Console.WriteLine(getdrives()[i].ToString());
                dir=new DirectoryInfo(getdrives()[i].ToString());
                files = dir.GetFiles("*.*");
               
                foreach (FileInfo fi in files)
                {

                    Console.WriteLine(fi.Name);
                }

            }

           
            Console.Read();
 
        }
        private static System.Collections.ArrayList getdrives()
        {
            System.Collections.ArrayList DriveArray = new System.Collections.ArrayList();
            DriveArray.AddRange(System.IO.DriveInfo.GetDrives().ToArray());
            return DriveArray;
        }
    }
}
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

In all fairness, you should split the points for this question and then ask another one.  

Author

Commented:
Thanks for attitude.i will solve myself only.

Commented:
Discovering solutions on your own is always a better ways to learn than just copying solution found on the internet. I can understand that.
I can't help myself, but due to the fact that you stated a question as is and get two capable answer, I think just deleting it igiving no point is kinda rude :-/

Commented:
question was asked, issue was solved in no time by two persons, question was reqeusted to be deleted.

Author

Commented:
ok

Author

Commented:
ok

Author

Commented:
ok

Author

Commented:
ok

Commented:
thank you for correcting that :-).
Btw. no offense, your allocation of points is fine to me.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial