Finding the create data of a file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have hundreds of files in a folder that I am reading using the File System
Object. I want to find the CreateDate of the file (i.e the file date as you
see it it Windows Explorer). I don't seem to be able to get it from the
FileSystem Object. Is there another object that will give me this info
please?
Regards
Stephen
 
Stephen,

Set your refs as per the attached gif, then use this:

Function GetCreateDate(tFileName As String) As String
'---------------------------------------------------------------------------------------
' Procedure : GetCreateDate
' DateTime : 11/21/2005 17:55
' Author : gmaddux
' Purpose : ']\ em: 20060706-16:36 - THIS NOW GETS THE DATE MODIFIED BECAUSE OUR SYSTEM CHANGES THE CREATE DATE
'---------------------------------------------------------------------------------------
'
On Error GoTo GetCreateDate_Error
Dim oFS As Scripting.FileSystemObject
Dim oFL As Scripting.File
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFL = oFS.GetFile(tFileName)

'GetCreateDate = Format$(oFL.DateCreated, "mm-dd-yyyy")
GetCreateDate = Format$(oFL.DateLastModified, "mm-dd-yyyy")

'Wscript.Echo "Date created: " & oFL.DateCreated
'Wscript.Echo "Date last accessed: " & oFL.DateLastAccessed
'Wscript.Echo "Date last modified: " & oFL.DateLastModified
'Wscript.Echo "Drive: " & oFL.Drive
'Wscript.Echo "Name: " & oFL.Name
'Wscript.Echo "Parent folder: " & oFL.ParentFolder
'Wscript.Echo "Path: " & oFL.Path
'Wscript.Echo "Short name: " & oFL.ShortName
'Wscript.Echo "Short path: " & oFL.ShortPath
'Wscript.Echo "Size: " & oFL.Size
'Wscript.Echo "Type: " & oFL.Type
GetCreateDate_Exit:
On Error GoTo 0

If Not (oFL Is Nothing) Then
Set oFL = Nothing
End If
If Not (oFS Is Nothing) Then
Set oFS = Nothing
End If

Exit Function
GetCreateDate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure GetCreateDate " & _
"of Module utils_nch"
GoTo GetCreateDate_Exit
Resume
End Function

NOTE: you should actually use the first property to get the createdate, BUT in my use, the files are copied from our server; so the actual create date is the previous modified date.

:) Gene
 

Attachments

  • vba_refs_fso.gif
    vba_refs_fso.gif
    7.6 KB · Views: 117
This may or may not work. Try:

'The following uses some of the FSO File's properties
'to display information about a file.

Private Sub displayFileInfo(ByVal fileName As String)
Dim fso As New FileSystemObject
Dim fileSpec As File
Dim strInfo As String
Set fileSpec = fso.GetFile(fileName)
strInfo = fileSpec.Name & vbCrLf
strInfo = strInfo & "Created: "
strInfo = strInfo & fileSpec.DateCreated & vbCrLf
strInfo = strInfo & "Last Accessed: "
strInfo = strInfo & fileSpec.DateLastAccessed & vbCrLf
strInfo = strInfo & "Last Modified: "
strInfo = strInfo & fileSpec.DateLastModified
MsgBox strInfo, vbInformation, "File Information"
Set fileSpec = Nothing
End Sub


jmonty
 
Back
Top