ba272
asked on
Setting the date and time for a file
Hi,
Back when I used Borland compilers, I used a function called, "touch( filename, datetime )", which would set the time and date of the file specified.
Does anybody know the equivalent in C#?
Thanks,
Bob
Back when I used Borland compilers, I used a function called, "touch( filename, datetime )", which would set the time and date of the file specified.
Does anybody know the equivalent in C#?
Thanks,
Bob
see System.IO.File.SetCreation Time() function
example :
System.IO.File.SetCreation Time(@"C:\ New File.txt", DateTime.Now);
System.IO.File.SetCreation
ASKER
It looks fine, and it compiles. But it doesn't work. Neither the file time nor date changes. And I close Windows Explorer first.
Any ideas?
Thanks.
Any ideas?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a bunch. It works perfect.
Try this code.... i have tried in my system its working fine....
=======================
using System.IO;
class Demo
{
public static void Main()
{
File.SetCreationTime(@"f:\ Book1.xls" , DateTime.Now);
File.SetLastAccessTime(@"f :\Book1.xl s", DateTime.Now);
File.SetLastWriteTime(@"f: \Book1.xls ", DateTime.Now);
}
}
========================
itsvtk
=======================
using System.IO;
class Demo
{
public static void Main()
{
File.SetCreationTime(@"f:\
File.SetLastAccessTime(@"f
File.SetLastWriteTime(@"f:
}
}
========================
itsvtk
ASKER
Thanks.