Solved

File modified Date

Posted on 2004-04-26
6
244 Views
Last Modified: 2010-05-02
Hello anyone know how to get the date/time a file was modified?  I know the FileDateTime function gets the date it was created, but need modified.  Thanks.

0
Comment
Question by:christampa
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
aelatik earned 100 total points
ID: 10921278
Easy scripting sample :

MsgBox CreateObject("Scripting.FileSystemObject").GetFile("c:\sites.inc").DateLastModified
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 10921305
To use aelatik's post you will need to add a Reference (Project -> References) to the 'Microsoft Scripting Runtime'.
0
 
LVL 14

Expert Comment

by:aelatik
ID: 10921325
jmwheeler,

CreateObject creates the object and does not need references
0
 
LVL 6

Expert Comment

by:PhilAI
ID: 10921422
Option Explicit

Private Const GENERIC_READ = &H80000000
Private Const OPEN_EXISTING = 3
Private Const FILE_ATTRIB_NORMAL = &H80

Private Type m_typFileTime
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type
Private Type m_typSystemTime
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As m_typFileTime, lpSystemTime As m_typSystemTime) As Long
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, ByVal lpCreationTime As Long, ByVal lpLastAccessTime As Long, lpLastWriteTime As m_typFileTime) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)

Private Function FileDateModified_Get(ByVal sFileFullname As String) As Date
' Returns the Modified Date of the passed file

Dim ftModified As m_typFileTime
Dim lpHandle As Long
Dim stModified As m_typSystemTime

On Error Resume Next

    lpHandle = CreateFile(sFileFullname, GENERIC_READ, 0&, 0&, OPEN_EXISTING, FILE_ATTRIB_NORMAL, ByVal 0&)
    If lpHandle > 0 Then
        Call GetFileTime(lpHandle, 0&, 0&, ftModified)
        Call FileTimeToSystemTime(ftModified, stModified)
        Call CloseHandle(lpHandle)

        With stModified
            FileDateModified_Get = CDate(.wDay & "/" & .wMonth & "/" & .wYear & " " & .wHour & ":" & .wMinute & ":" & .wSecond)
        End With
    End If

End Function

Private Sub Form_Load()
    MsgBox FileDateModified_Get("C:\myFile.txt")
End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

930 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

12 Experts available now in Live!

Get 1:1 Help Now