Getting rid of *consecutive* periods in a filename
<p>I was wondering how I'd get rid of periods in a filename if i have a filename like:</p>

<p>Test....1.txt to look like Test 1.txt ?  I do NOT want files like :  1.0.1 Test.txt to be touched.  Only files with consecutive periods should be replaced with a space.  Any ideas?</p>

<p>This is my current code but as you can see, it replaces every period aside from periods in extension names:</p>

<pre><code> public void DoublepCleanUp(List&lt;string&gt; doublepFiles)
    {
        Regex regExPattern2 = new Regex(@"\s{2,}");
        Regex regExPattern4 = new Regex(@"\.+");
        Regex regExPattern3 = new Regex(@"\.(?=.*\.)");
        string replace = " ";
        List&lt;string&gt; doublep = new List&lt;string&gt;();
        var filesCount = new Dictionary&lt;string, int&gt;();

        try
        {
            foreach (string invalidFiles in doublepFiles)
            {
                string fileOnly = System.IO.Path.GetFileName(invalidFiles);
                string pathOnly = System.IO.Path.GetDirectoryName(fileOnly);

                if (!System.IO.File.Exists(fileOnly))
                {
                    string filewithDoublePName = System.IO.Path.GetFileName(invalidFiles);
                    string doublepPath = System.IO.Path.GetDirectoryName(invalidFiles);
                    string name = System.IO.Path.GetFileNameWithoutExtension(invalidFiles);
                    //string newName = name.Replace(".", " ");
                    string newName = regExPattern4.Replace(name, replace);
                    string newName2 = regExPattern2.Replace(newName, replace);
                    string filesDir = System.IO.Path.GetDirectoryName(invalidFiles);
                    string fileExt = System.IO.Path.GetExtension(invalidFiles);
                    string fileWithExt = newName2 + fileExt;
                    string newPath = System.IO.Path.Combine(filesDir, fileWithExt);
                    System.IO.File.Move(invalidFiles, newPath);


                    DataGridViewRow clean = new DataGridViewRow();
                    clean.CreateCells(dataGridView1);
                    clean.Cells[0].Value = doublepPath;
                    clean.Cells[1].Value = filewithDoublePName;
                    clean.Cells[2].Value = fileWithExt;
                    dataGridView1.Rows.Add(clean);
                }

                else
                {
                    if (filesCount.ContainsKey(fileOnly))
                    {
                        filesCount[fileOnly]++;
                    }
                    else
                    {
                        filesCount.Add(fileOnly, 1);
                        string newFileName = String.Format("{0}{1}{2}",
                            System.IO.Path.GetFileNameWithoutExtension(fileOnly),
                            filesCount[fileOnly].ToString(),
                            System.IO.Path.GetExtension(fileOnly));

                        string newFilePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(fileOnly), newFileName);
                        System.IO.File.Move(fileOnly, newFilePath);

                        DataGridViewRow clean = new DataGridViewRow();
                        clean.CreateCells(dataGridView1);
                        clean.Cells[0].Value = pathOnly;
                        clean.Cells[1].Value = fileOnly;
                        clean.Cells[2].Value = newFileName;
                        dataGridView1.Rows.Add(clean);
                    }

                }
            }
        }
         catch(Exception e)
         {
         //throw;
             StreamWriter doublepcleanup = new StreamWriter(@"G:\DoublePeriodCleanup_Errors.txt");
             doublepcleanup.Write("Double Period Error: " + e + "\r\n");
             doublepcleanup.Close();
         }

        }
</code></pre>
