Link to home
Start Free TrialLog in
Avatar of wademi
wademi

asked on

C# control stucture

I am using the following code to check the contents of a fodler then output the name of the folder missing specific file types.Example(.mov,.mpeg)

Its a console application. So I may run the following  from cmd.
C:\Consoleapplication1.exe FolderX (.mov,.mpeg)


Here is the code

public static void Main(String[] args)
{
      if (args.Length != 2)
      {
            Console.WriteLine("Invalid parameters");
            return;
      }
      
      MatchCollection extensions = Regex.Matches(args[1], @"\.\w+");
      
      using (StreamWriter writer = new StreamWriter("MyOutputFile.txt"))
      {
            foreach (string dir in Directory.GetDirectories(args[0], "*", SearchOption.AllDirectories))
            {
                  foreach (Match extension in extensions)
                  {
                        if (Directory.GetFiles(dir, "*" + extension.Value).Length == 0)
                        {
                              writer.WriteLine("{0}: Missing: {1}", dir, extension.Value);
                        }
                  }
            }
      }
}



The problem with the current control is if  it checks for example a directorywith only a  .Mov file  for a .mpeg file first  it outputs the  folder as missing a movie file. This occurs because the .MOv file may be checked last.

I need to ensure that the folders are checked for every file type and only outputs the folder if none of the files in the loop exsist in the folder.

How can I modify my code to achieve the above?
ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand 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
BTW, I didn't test...