Hi All,
I am trying to copy specific files from a share to a local temp folder on a specified date (not yet implemented)
The trouble I am seeing is that I am trying to use a wildcard within the files as they have random numbers after set characters to which it errors with illegal characters in path.
Any help would be greatly appreciated.
private void WedArrears()
{
string nLine = Environment.NewLine;
DateTime date = DateTime.Now;
if (date.DayOfWeek.Equals(DayOfWeek.Wednesday))
{
string dpPath = @Properties.Settings.Default.DPPath; // target directory c:\Temp
string wedTemp = @Properties.Settings.Default.WedTmpFiles; //source directory \\yhn\spool$\houlive\hou_output
try
{
string[] patterns = new string[] { "GA1*.rtf", "GA2*.rtf", "INTW*.rtf", "LET1*.rtf", "RA2*.rtf", "RA3*.rtf", "A4*.rtf", "RA5*.rtf" };
var matches = patterns.SelectMany(pat => Directory.GetFiles(wedTemp)
.Where(path => System.Text.RegularExpressions.Regex.Match(wedTemp, pat).Success));
foreach (string file in patterns)
{
string dest = dpPath + file;
string source = wedTemp + file;
File.Copy(source, dest);
textResults.AppendText(file + nLine);
}
}
catch (IOException ex)
{
textResults.AppendText(ex + nLine);
}
MessageBox.Show("Successfully Copied Files");
}
}