我有一个 C# 脚本,它当前正在两个目录之间移动文件。它一次移动 10 个文件。问题是它按文件名抓取 10 个文件。我希望它每次运行时都能抓取最旧的 10 个文件。我怎样才能做到这一点?
目前,我的脚本如下所示:
string[] dirsSourceDirectory = System.IO.Directory.GetDirectories(sourceDirectory);
string[] filesSourceDirectory = System.IO.Directory.GetFiles(sourceDirectory);
string[] dirsDestinationDirectory = System.IO.Directory.GetDirectories(destinationDirectory);
string[] filesDestinationDirectory = System.IO.Directory.GetFiles(destinationDirectory);
int filecount = Directory.GetFiles(destinationDirectory, "*.TRN", SearchOption.TopDirectoryOnly).Length;
for (int i = 1; i <= 10; i++)
{
FileInfo[] rgfiles = di.GetFiles();
rgfiles[0].MoveTo(System.IO.Path.Combine(destinationDirectory, rgfiles[0].Name));
}
谢谢!