Solved

File modified Date

Posted on 2004-04-26
6
247 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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.
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…
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…

856 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