C#中的上次文件时间 [英] Last file time in C#
本文介绍了C#中的上次文件时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试着获取文件的时间。 scanerio是当任何最后一个文件保存在文件夹中我希望在控制台中的文件日期时间
i试试这个
我有什么试过:
i try to get time of file. scanerio is when any last file is saved in folder i want that file date time in console
i try this
What I have tried:
public static void Main()
{
try
{
string path = @"C:\Users\Administrator\Desktop\New folder\DB.txt";
if(!File.Exists(path))
{
File.Create(path);
}
else
{
File.SetLastWriteTime(path, new DateTime());
}
DateTime dt = File.GetLastWriteTime(path);
Console.WriteLine("the last time {0}", dt);
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
但这显示错误
Not一个有效的Win32 FileTime。
任何解决方案
but this shows error
Not a valid Win32 FileTime.
any solution
推荐答案
你想通过以下代码行实现什么?
What you want to achieve through following line of code?
File.SetLastWriteTime(path, new DateTime());
如果要将当前日期时间设置为LastWriteTime,请尝试以下操作 -
If you want to set current datetime as LastWriteTime, try following-
File.SetLastWriteTime(path, DateTime.Now);
如果您仍然遇到相同的错误或者您的要求是其他原因,请告诉我。
:)
If you still experience the same error or if your requirement is something else, please let me know.
:)
>
这篇关于C#中的上次文件时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文