[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2007-10-10
14
Medium Priority
?
839 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?
0
Comment
Question by:DanielAttard
  • 8
  • 6
14 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 20051105
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
 

Author Comment

by:DanielAttard
ID: 20051253
Thanks for the response.  

What does this mean?:  Imports System.IO


0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 20051334
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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

Author Comment

by:DanielAttard
ID: 20051462
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
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 20051631
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
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 20051641
I used a TextBox on a form to get the directory to do the work on.
0
 

Author Comment

by:DanielAttard
ID: 20051701
Thank you.  I will try your solution later and post back once I have it working.  I appreciate your help.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 20051720
OK
0
 

Author Comment

by:DanielAttard
ID: 20069945
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
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 20070204
You probably could but I have never used MS Access VBA before. You have a copy of Visual Basic .Net 2005?
0
 

Author Comment

by:DanielAttard
ID: 20070873
Yes, I have VB.Net 2005.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 20070985
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
 

Author Comment

by:DanielAttard
ID: 20071286
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
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 20071312
Not a problem, glad I was able to help in the learning process. ;=)
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Screencast - Getting to Know the Pipeline

829 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