本文实例讲述了C#获取指定目录最后写入时间的方法。分享给大家供大家参考。具体如下:
C#返回指定目录最后写入时间,主要用到了DirectoryInfo的LastWriteTime属性
using System;using System.IO;class MainClass { static void Main(string[] args) { FileInfo file = new FileInfo("c://a.txt"); // Display directory information. DirectoryInfo dir = file.Directory; Console.WriteLine("Checking directory: " + dir.Name); Console.WriteLine("In directory: " + dir.Name); Console.Write("Directory exists: "); Console.WriteLine(dir.Exists.ToString()); if (dir.Exists) { Console.Write("Directory last updated: "); Console.WriteLine(dir.LastWriteTime.ToString()); } Console.WriteLine(); }}
希望本文所述对大家的C#程序设计有所帮助。
新闻热点
疑难解答