我正在尝试查找具有最后写入日期的文件并将其复制到其他位置。它正确找到了文件,但是当我尝试复制它时,它找不到刚刚找到的文件。这是在 SSIS 脚本任务中。
DirectoryInfo directory = new DirectoryInfo(@"path");
FileInfo[] files = directory.GetFiles();
//files that have been written to in the last 3 days
DateTime lastWrite = DateTime.Now.AddDays(-3);
foreach (FileInfo latestFile in files)
{
// if its the correct name
if (latestFile.Name.StartsWith("OMC"))
{
// if its in the last 3 days
if (latestFile.LastWriteTime > lastWrite)
{
lastWrite = latestFile.LastWriteTime;
// this correctly find the file and puts it into the file variable.
file = latestFile.ToString();
// this errors out saying it cannot find the file.
// (Does not even go to the outputFile)
File.Copy(file, outputFile, true); // <- error
//backs the file up
File.Copy(file, backupfile, true);
}
}
}