• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 859
  • Last Modified:

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

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?
0
DanielAttard
Asked:
DanielAttard
  • 8
  • 6
1 Solution
 
Fernando SotoRetiredCommented:
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
0
 
DanielAttardAuthor Commented:
Thanks for the response.  

What does this mean?:  Imports System.IO


0
 
Fernando SotoRetiredCommented:
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
DanielAttardAuthor 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.
0
 
Fernando SotoRetiredCommented:
Hi DanielAttard;

Here is what you need using FileInfo object in place of the File object.

Imports System.IO

        Dim DirectoryPath As String = TextBox1.Text.Trim()
        If Not Directory.Exists(DirectoryPath) Then
            MessageBox.Show("Directory does not exist, please correct.")
            Return
        End If

        Dim DirInfo As New DirectoryInfo(DirectoryPath)
        Dim FInfos() As FileInfo = DirInfo.GetFiles()
        For Each FInfo As FileInfo In FInfos
            Dim MDate As DateTime = FInfo.LastWriteTime()
            FInfo.CreationTime = MDate
        Next

Fernando
0
 
Fernando SotoRetiredCommented:
I used a TextBox on a form to get the directory to do the work on.
0
 
DanielAttardAuthor Commented:
Thank you.  I will try your solution later and post back once I have it working.  I appreciate your help.
0
 
Fernando SotoRetiredCommented:
OK
0
 
DanielAttardAuthor 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,
0
 
Fernando SotoRetiredCommented:
You probably could but I have never used MS Access VBA before. You have a copy of Visual Basic .Net 2005?
0
 
DanielAttardAuthor Commented:
Yes, I have VB.Net 2005.
0
 
Fernando SotoRetiredCommented:
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
0
 
DanielAttardAuthor 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!
0
 
Fernando SotoRetiredCommented:
Not a problem, glad I was able to help in the learning process. ;=)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now