We help IT Professionals succeed at work.

How do I replace the file attribute DATE CREATED, with DATE MODIFIED?

915 Views
Last Modified: 2008-01-09
I have several hundred files where the DATE CREATED is incorrect, but the DATE MODIFIED is correct.

How can I write the value of the DATE MODIFIED attribute, into the DATE CREATED attribute?
Comment
Watch Question

Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
Hi DanielAttard;

This will do it.

Imports System.IO

        ' File who's creation date is to be modified
        Dim fName As String = "C:\Temp\aBook.csv"
        Dim dt As DateTime = File.GetLastWriteTime(fName)
        File.SetCreationTime(fName, dt)

Fernando

Author

Commented:
Thanks for the response.  

What does this mean?:  Imports System.IO


Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
If you place the Imports statement at the top of the source file of a Visual Basic .Net program then you do not have to fully qualify the object that use the System IO library which means you can use the lines of code as posted.

        ' File who's creation date is to be modified
        Dim fName As String = "C:\Temp\aBook.csv"
        Dim dt As DateTime = File.GetLastWriteTime(fName)
        File.SetCreationTime(fName, dt)

If you do not use the Imports statement then the above code must be modified to the following.

        ' File who's creation date is to be modified
        Dim fName As String = "C:\Temp\aBook.csv"
        Dim dt As DateTime = System.IO.File.GetLastWriteTime(fName)
        System.IO.File.SetCreationTime(fName, dt)

So basically it cuts down on the typing you have to do.

Author

Commented:
That's great.  Thank you.  

Now I just need to figure out a way to loop through each of the files in the specified folder, and then run your code on each of the files.
Retired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
I used a TextBox on a form to get the directory to do the work on.

Author

Commented:
Thank you.  I will try your solution later and post back once I have it working.  I appreciate your help.
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
OK

Author

Commented:
Hi Fernando,

I'm still stuck.  I understand some VB programming, but I'm not too familiar with .Net.

Is there some way of implementing your solution without doing it as a Visual Basic .Net program?

Could I do it in MS Access VBA somehow?

Thanks,
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
You probably could but I have never used MS Access VBA before. You have a copy of Visual Basic .Net 2005?

Author

Commented:
Yes, I have VB.Net 2005.
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
Hi DanielAttard;

I put a small program together to do what you need. Download this project, unzip it and open in Visual Basic .Net 2005 and compile/Build it.

     https://filedb.experts-exchange.com/incoming/ee-stuff/5004-ResetCreationDate.zip

Fernando

Author

Commented:
Thank you FernandoSoto.  Not only did it work flawlessly, but more importantly, it provided me with a few of those special "Aha!" moments when learning takes place.  Thanks for helping me to learn.  I love this site!
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
Not a problem, glad I was able to help in the learning process. ;=)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.