I have the following lines of code:
protected void MoveFilesToInBound(string filePath, string fileName, DateTime? reportingRun)
{
var dateValue = reportingRun.Value.ToString("yyyyMMdd");
var file = fileName + "_" + dateValue + ".csv";
if (File.Exists(Path.Combine(filePath, file)))
{
File.Copy(file, InputFolder);
}
}
Could not find file 'myFile_20170831.csv'
File.Copy
Well, you are not using the same paths...:
if (File.Exists(Path.Combine(filePath, file)))
{
File.Copy(file, InputFolder);
}
Path.Combine(filePath, file)
is, hopefully, not the same as file
. Didn't you mean to use:
if (File.Exists(Path.Combine(filePath, file)))
{
File.Copy(Path.Combine(filePath, file), InputFolder);
}
I said "hopefully" because, if file
was a full path ("C:\.."), Path.Combine
would return file
instead of the combination.
Also, in order to gain some performance, you should be using:
string filePath = Path.Combine(filePath, file);
if (File.Exists(filePath))
{
File.Copy(filePath, InputFolder);
}