Solved

File modified Date

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

831 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