Solved

File modified Date

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

762 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

20 Experts available now in Live!

Get 1:1 Help Now