在c#中读取文件夹内的文本文件 [英] Reading text file inside the Folder in c#

查看:79
本文介绍了在c#中读取文件夹内的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主文件夹示例中有5个不同的文本文件



c:\ Main



在Main中,我有5个文件(test1.txt,test2.txt.test3.txt,test4.txt和test5.txt)



如何阅读最新文件?

I have 5 different text file inside the Main Folder example

c:\Main

inside Main, i have 5 file (test1.txt, test2.txt. test3.txt, test4.txt and test5.txt)

How to read the latest file?

推荐答案

通过获取以下时间来添加对Createdon的检查:

Add check on Createdon by getting time like below:
static void Main(string[] args)
       {
           DateTime fileCreatedDate = File.GetCreationTime(@"C:\Example\MyTest.txt");
           Console.WriteLine("file created: " + fileCreatedDate);
       }


您好,

您可以使用
Hi,
you can use
System.IO.File.GetCreationTime()



此方法提供文件的创建日期和时间。

您还可以在文件名中指定订单或创建日期。


This methods gives the creation date and time of your file.
you can also specify an order or a creation date in your file name.


您需要列出目录中的所有文件并检查最后写的文件。





看看这里:

如何to:枚举目录和文件 [ ^ ]

FileSystemInfo.LastWriteTime属性 [ ^ ]

如何:从文本文件中读取(C#编程指南) [ ^ ]
You need to list all files in a directory and check which was lastly writen.


Have a look here:
How to: Enumerate Directories and Files[^]
FileSystemInfo.LastWriteTime Property[^]
How to: Read From a Text File (C# Programming Guide)[^]

这篇关于在c#中读取文件夹内的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆