Reading a files timestamp

Posted on 2006-05-07
Last Modified: 2010-05-01
How do you read a files timestamp using a visual basic application?
Question by:Ray2006
    LVL 23

    Expert Comment

    Do you mean last modified, created or last accessed?
    The inforreader object can give you all of these:

    Dim infoReader As System.IO.FileInfo
    infoReader = My.Computer.FileSystem.GetFileInfo("C:\testfile.txt")
    MsgBox("File was last modified on " & infoReader.LastWriteTime)
    LVL 6

    Expert Comment

    basicinstinct's code is VB.NET . If you are using VB6, it should be:

        Dim myFSO As Object
        Dim myFile As Object
        Set myFSO = CreateObject("Scripting.FileSystemObject")
        Set myFile = myFSO.GetFile("c:\111.txt")
        Debug.Print myFile.DateCreated, myFile.DateLastAccessed, myFile.DateLastModified
    LVL 85

    Accepted Solution

    Without FSO, you can get the "date and time when a file was created or last modified" using the FileDateTime() function:

        Dim fileName As String
        Dim lastModified As Date
        fileName = "c:\someFile.txt"
        lastModified = FileDateTime(fileName)
        Debug.Print lastModified

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now