我有文本文件列表,我需要C#工具来查找最后创建的文件并将其加载到SQL中,我每天第一天在05:15 AM和12:15 AM进行两次工作,并生成两个文本文件(genset_20090103_1212.TXT),我需要获取最后创建的一个并将其数据附加到sql
you can do it using linq
var directory = new DirectoryInfo("C:\\MyDirectory")
var lastcreatedfile = (from c in directory.GetFiles()
orderby c.CreationTime descending
select c).First();
string text = System.IO.File.ReadAllText("C:\\MyDirectory"+lastcreatedfile.FullName+".txt");
insert the content text to your sql
Please try this code.
FileInfo file1Info = new FileInfo("File1.txt");
FileInfo file2Info = new FileInfo("File2.txt");
if (file1Info.LastWriteTime < file2Info.LastWriteTime)
{
//Insert File2.txt in your Database
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.