Keith Maurino
Keith Maurino

Reputation: 3432

Get a file's last modified date in VB6

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

Upvotes: 9

Views: 38437

Answers (6)

Ovidiu Luca
Ovidiu Luca

Reputation: 91

I use this native code to update the date-modified in VB6:

Dim nUnit As Integer
nUnit = FreeFile
Open "C:\file.txt" For Append As nUnit
Print #nUnit, ""
Close #nUnit

It's has a similar efect to Linux 'touch' command.

Upvotes: 0

Gary O'Connor
Gary O'Connor

Reputation: 31

This is definitely the easiest way to achieve what you are looking for.

Dim myString as String

Dim myDate As Date

myString = Format(FileDateTime("C:\TESTFILE.txt"), "dd-MM-yyyy")

myDate = MyString

If you dim your variable as a string, you can use the Format function to shorten the result to just the date.

If you need your variable to be declared as a Date then do as I have done above and declare that as a separate variable. Once the Format function has done its job, copy the String variable to the Date variable and you're done in two lines of code.

As simple as that.

Upvotes: 3

Belmiris
Belmiris

Reputation: 2805

I would recommend using the windows api call: http://www.ex-designz.net/apidetail.asp?api_id=128

Then you can get either creation date or last modified date.

Upvotes: 0

DJ.
DJ.

Reputation: 16247

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")

Upvotes: 26

raven
raven

Reputation: 18135

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

Upvotes: 3

JoshBerke
JoshBerke

Reputation: 67068

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.

Upvotes: 0

Related Questions