anon
anon

Reputation:

VBScript - Object doesn't support this property or method: DateCreated

I am trying to use this property in VBScript: DateCreated, as described here: http://msdn.microsoft.com/en-us/library/ke6a7czx%28v=vs.84%29.aspx

But I get the following error: Microsoft VBSCript runtime error:

Object doesn't support this property or method: 'objFSO.DateCreated'

I cannot find any information on the internet, can somebody help?

This is a piece of my code:

Function showFile( str )
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objReadFile = objFSO.OpenTextFile( str , 1, False)

    contents = objReadFile.ReadAll
    objReadFile.close

    strCreated= objFSO.DateCreated

Upvotes: 1

Views: 21562

Answers (1)

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56727

You're not getting a File or Folder object in your code, but you're trying to invoke the method on the FileSystemObject (the ActiveX Component itself).

You need to get a File object for a specific file name to invoke DateCreated on as described in the MSDN sample code on the page you linked in your question:

Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
ShowFileInfo = "Created: " & f.DateCreated

They are calling GetFile on the FileSystemObject to actually get the File object.

Upvotes: 7

Related Questions