Getting an index outside bound of an array in C#
<p>This program is supposed to show the path of a directory and the directory if its exists then it should also show the files inside with the following extensions (i.e .doc, .pdf, .jpg, .jpeg) but I'm getting an error </p>

<blockquote>
  <p>*Index was outside the bounds of the array.</p>
</blockquote>

<p>on this line of code</p>

<pre><code>string directoryPath = args[0];
</code></pre>

<p>This is the code in the main function</p>

<pre><code> class Program
    {
        static void Main(string[] args)
        {

                string directoryPath = args[0];
                string[] filesList, filesListTmp;
                IFileOperation[] opList = { new FileProcNameAfter10(),
                                            new FileProcEnc(),
                                            new FileProcByExt("jpeg"),
                                            new FileProcByExt("jpg"),
                                            new FileProcByExt("doc"),
                                            new FileProcByExt("pdf"),
                                            new FileProcByExt("djvu")
                                            };
                if (Directory.Exists(directoryPath))
                {
                    filesList = Directory.GetFiles(directoryPath);
                    while (true)
                    {
                        Thread.Sleep(500);
                        filesListTmp = Directory.GetFiles(directoryPath);
                        foreach (var elem in Enumerable.Except&lt;string&gt;(filesListTmp, filesList))
                        {
                            Console.WriteLine(elem);
                            foreach (var op in opList)
                            {
                                if (op.Accept(elem)) op.Process(elem);
                            }
                        }
                        filesList = filesListTmp;
                        if (Console.KeyAvailable == true &amp;&amp; Console.ReadKey(true).Key == ConsoleKey.Escape) break;
                    }
                }
                else
                {
                    Console.WriteLine("There is no such directory.");

                }


        }
    }
</code></pre>

<p>How can I handle this error it seems to be common but it happens id different ways </p>
