开发者

Get a file's last modified date in VB6

How do you ge开发者_如何学JAVAt any file's last modified date using VB6?


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


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


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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜