Trying to delete multiple files from a single directory whose names match\contain a particular string
<p>I wish to delete image files. The files are named <code>somefile.jpg</code> and <code>somefile_t.jpg</code>, the file with the <code>_t</code> on the end is the thumbnail. With this delete operation I wish to delete both the thumbnail and original image.</p>

<p>The code works up until the <code>foreach</code> loop, where the <code>GetFiles</code> method returns nothing.
The string.Substring operation successfully returns just the file name with no extension and no <code>_t</code> e.g: <code>somefile</code>.</p>

<p>There are no invalid characters in the file names I wish to delete.
Code looks good to me, only thing I can think of is that I am somehow not using the searchpattern
function properly.</p>

<pre><code>filesource = "~/somedir/somefile_t.jpg"
</code></pre>

<hr>

<pre><code>var dir = Server.MapPath(filesource);


            FileInfo FileToDelete = new FileInfo(dir);


            if (FileToDelete.Exists) 
            { 
                var FileName = Path.GetFileNameWithoutExtension(FileToDelete.Name);

                foreach(FileInfo file in FileToDelete.Directory.GetFiles(FileName.Substring(0, FileName.Length - 2), SearchOption.TopDirectoryOnly).ToList())
               {
                   file.Delete();
               }

            }
</code></pre>
