想变更文件夹的时间.以前做了一个软件.是变更文件的时间,应用了C# API.这次和上一次相同,用Form来通过外部对时间进行确认.确认后应用C#中,System.IO ->Directory->SetCreationTime 来对时间进行变更.
以下是C#应用的例子.基本相同.但是,不要忘记小问题,下面的例子的命名空间,和函数的调用.
C#
// This sample shows the differences between dates from methods that use //coordinated universal time (UTC) format and those that do not. using System; using System.IO; namespace IOSamples {public class DirectoryUTCTime{public static void Main(){// Set the directory.string n = @"C:\test\newdir";//Create two variables to use to set the time.DateTime dtime1 = new DateTime(2002, 1, 3);DateTime dtime2 = new DateTime(1999, 1, 1);//Create the directory.try{Directory.CreateDirectory(n);}catch (IOException e){Console.WriteLine(e);}//Set the creation and last access times to a variable DateTime value.Directory.SetCreationTime(n, dtime1);Directory.SetLastAccessTimeUtc(n, dtime1);// Print to console the results.Console.WriteLine("Creation Date: {0}", Directory.GetCreationTime(n));Console.WriteLine("UTC creation Date: {0}", Directory.GetCreationTimeUtc(n));Console.WriteLine("Last write time: {0}", Directory.GetLastWriteTime(n));Console.WriteLine("UTC last write time: {0}", Directory.GetLastWriteTimeUtc(n));Console.WriteLine("Last access time: {0}", Directory.GetLastAccessTime(n));Console.WriteLine("UTC last access time: {0}", Directory.GetLastAccessTimeUtc(n));//Set the last write time to a different value.Directory.SetLastWriteTimeUtc(n, dtime2);Console.WriteLine("Changed last write time: {0}", Directory.GetLastWriteTimeUtc(n));}} } // Obviously, since this sample deals with dates and times, the output will vary // depending on when you run the executable. Here is one example of the output: //Creation Date: 1/3/2002 12:00:00 AM //UTC creation Date: 1/3/2002 8:00:00 AM //Last write time: 12/31/1998 4:00:00 PM //UTC last write time: 1/1/1999 12:00:00 AM //Last access time: 1/2/2002 4:00:00 PM //UTC last access time: 1/3/2002 12:00:00 AM //Changed last write time: 1/1/1999 12:00:00 AM