Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Reading a files timestamp

How do you read a files timestamp using a visual basic application?
0
Ray2006
Asked:
Ray2006
1 Solution
 
basicinstinctCommented:
Do you mean last modified, created or last accessed?
The inforreader object can give you all of these:

Dim infoReader As System.IO.FileInfo
infoReader = My.Computer.FileSystem.GetFileInfo("C:\testfile.txt")
MsgBox("File was last modified on " & infoReader.LastWriteTime)

http://msdn2.microsoft.com/en-US/library/zds3tce6.aspx
0
 
junglerover77Commented:
basicinstinct's code is VB.NET . If you are using VB6, it should be:

    Dim myFSO As Object
    Dim myFile As Object
   
    Set myFSO = CreateObject("Scripting.FileSystemObject")
    Set myFile = myFSO.GetFile("c:\111.txt")
    Debug.Print myFile.DateCreated, myFile.DateLastAccessed, myFile.DateLastModified
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Without FSO, you can get the "date and time when a file was created or last modified" using the FileDateTime() function:

    Dim fileName As String
    Dim lastModified As Date
   
    fileName = "c:\someFile.txt"
    lastModified = FileDateTime(fileName)
    Debug.Print lastModified
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now