[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Setting the date and time for a file

Posted on 2005-03-04
7
Medium Priority
?
372 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

649 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