?
Solved

Setting the date and time for a file

Posted on 2005-03-04
7
Medium Priority
?
369 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:ba272
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 19

Expert Comment

by:Fahad Mukhtar
ID: 13464448
see System.IO.File.SetCreationTime() function
0
 
LVL 19

Expert Comment

by:Fahad Mukhtar
ID: 13464456
example :
System.IO.File.SetCreationTime(@"C:\New File.txt", DateTime.Now);
0
 

Author Comment

by:ba272
ID: 13464562
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 19

Accepted Solution

by:
Fahad Mukhtar earned 2000 total points
ID: 13464696
i think you are looking for last modified time instead of creation time...:

//Set Creation time for a file
System.IO.File.SetCreationTime(@"C:\New File.txt", DateTime.Now);
//Set last modified time (see that in the exploree window)
System.IO.File.SetLastWriteTime(@"C:\New File.txt", DateTime.Now);

right click the file icon and see the last created and modified properties..
0
 

Author Comment

by:ba272
ID: 13464706
Thanks a bunch.  It works perfect.
0
 
LVL 14

Expert Comment

by:Thandava Vallepalli
ID: 13464756
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.xls", DateTime.Now);
            File.SetLastWriteTime(@"f:\Book1.xls", DateTime.Now);
      }
}
========================

itsvtk
0
 

Author Comment

by:ba272
ID: 13466110
Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question