Link to home
Start Free TrialLog in
Avatar of GarySB
GarySB

asked on

How to read File Date Created using VB6

Using Visual Basic 6.
FileDateTime only gives the Date Modified.
I need to read the Date Created and have it work on XP, Vista and Win7.
The FileSystemObject seems to warn about compatibility problems.
Please provide a vb6 example, Thank You
Avatar of JesterToo
JesterToo
Flag of United States of America image

Something like this should work.  Might have some syntactical issues... kinda wrote it off top of my head and I don't have a machne with a VB6 compiler available at the moment.  Should work on any Windows machine if it has FileSystemObject installed.

Option Explicit

Public main()
   Dim sArgs As String
   Dim n As Integer

   sArgs = Split(Command$, " ")

   If UBound(sArgs) = 0 Then

   End If

   Debug.Print ShowFileDates(sArgs0)


Function ShowFileDates(fileSpec)
   Dim fso, f, s
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFile(fileSpec)
   s = f.Path & "<br>"
   s = s & "Created: " & f.DateCreated & "<br>"
   s = s & "Last Accessed: " & f.DateLastAccessed & "<br>"
   s = s & "Last Modified: " & f.DateLastModified
   ShowFileDates = s
End Function

Open in new window

Avatar of GarySB
GarySB

ASKER

If it has FileSystemObject installed is the exact issue I read about.
My goal is to read when my program was installed.
Can  FileSystemObject be included with my setup package to ensure the user will have it or will that cause a problem?
I have to be sure not to cause an error.
* Is it possible instead to read the created date of a registry entry, folder or something else?
Thank You
SOLUTION
Avatar of JesterToo
JesterToo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry this took so long but I've had several "out of the office" type issues over the past few days... and, there was quite a bit of leg-work to do to come up with a solution I think you might like.

Quick recap is I created a VB6 console app (yes console... runs in command prompt window rather than gui forms) that uses only Win32 API calls for all screen and file I/O.  The executable is capable of displaying all 3 timestamps a file has (but, read the "readme.txt" file in the attached archive to find out how to enable Windows OS from Vista thru Win10 to actually track Last Access timestamp).  The mere act of running the executable will update its Last Access timestamp... so if you should run a different copy of the executable than the one you want to view.  It's OK to rename it if you want.

Normal usage would be to run "ShowTimes pathtosomefilename" from a command prompt.  If you omit the filename argument the app looks for a file by its own name.

That would be equivalent to ShowTimes ShowTimes.exe
If you renamed it then equiv. would be:  newexename newexename

Here is a zip archive of the entire project and documentation of how to build/modify it.
ShowTimes.zip
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GarySB

ASKER

Thank you for the examples.  I'll try them today and let you know how it worked.
Avatar of GarySB

ASKER

Thank You, I have what I need now
You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015 and 2016
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2016