Link to home
Start Free TrialLog in
Avatar of trevor1940
trevor1940

asked on

C#: Finding directories with *.avi files

Hi

I'm trying to find all the directories that contain an *.avi file so I can move the directory
Doesn't matter if other files type exist in the same directory

In the code bellow I'm finding every directory even with no avi

           string[] Dirs = Directory.GetDirectories(Root, "*", SearchOption.TopDirectoryOnly);
            foreach (string Dir in Dirs)
            {
                string NewDir = "";
                string[] Files = Directory.GetFiles(Dir, "*.avi", SearchOption.TopDirectoryOnly);

                // If a no avi file in Dir Files should not be  null  ??

                if (Files != null ) //|| Files.Count() >= 1)
                {
                    NewDir = avi_files + Dir;
                    string OldDir = Root + "\\" + Dir;
                    if (!Directory.Exists(NewDir))
                    {

                        //   Directory.Move(OldDir, NewDir);
                        Console.WriteLine("OldDir: {0} NewDir: {1} ", OldDir, NewDir);
                    }
                }
 
           }

Open in new window


The first Dir dose not have an *.avi file but in the "Immediate window"
Files != null
true

Open in new window

That means Files has an avi file ??

as you can see in the code i've tried different methods
var files = Directory.EnumerateFiles(Root, "*.*", SearchOption.AllDirectories)
                    .Where(s => s.EndsWith("*.AVI") || s.EndsWith("*.avi"));

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trevor1940
trevor1940

ASKER

Thank you.