tags:

views:

245

answers:

4

How do you get any file's last modified date using VB6?

+1  A: 

You can use the FileSystemObject here's an example

You can also check out the MSDN documentation the samples are for scripting but they should be translatable to VB6 easily.

JoshBerke
-1. I recommend avoiding FileSystemObject if possible. It's not always present on user machines. We had a helpdesk problem last month because a paranoid IT department had crippled FileSystemObject, and that broke some software we maintain. Also this can be done in one line in native VB6, not 4 lines of FileSystemObject.
MarkJ
+1  A: 

MSDN Link

Dim fs As New Scripting.FileSystemObject
Dim f
Set f = fs.GetFile("path/to/file")
f.DateLastModified
Mark
+1  A: 

Add a reference to the Microsoft Scripting Runtime (Project->References...) and use the following code:

Dim fso As New FileSystemObject
Dim fil As File

Set fil = fso.GetFile("C:\foo.txt")
Debug.Print fil.DateLastModified
raven
-1. I recommend avoiding FileSystemObject if possible. It's not always present on user machines. We had a helpdesk problem last month because a paranoid IT department had crippled FileSystemObject, and that broke some software we maintain. Also this can be done in one line in native VB6: must be better than 4 lines with FileSystemObject.
MarkJ
+6  A: 

There is a built in VB6 function for that - no need for FSO (although FSO is great for more advanced file operations)

From http://msdn.microsoft.com/en-us/library/aa262740%28VS.60%29.aspx

Dim MyStamp As Date
MyStamp = FileDateTime("C:\TESTFILE.txt")
DJ
+1. I recommend avoiding FileSystemObject if possible. It's not always present on user machines. We had a helpdesk problem last month because a paranoid IT department had crippled FileSystemObject, and that broke some software we maintain. Here the native VB6 technique is one line, and the FSO code is at least 3 lines.
MarkJ