Results 1 to 3 of 3

Thread: How to display date in FileListBox

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Slovenia
    Posts
    40
    Hello
    I vould like to display date of file's last change in FileListBox near file name.
    Can anybody help me?
    Tomaz

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    http://www.vbapi.com/ref/g/getfiletime.html

    Has got what you want. The best I came up with (which may help or point you in the right direction is the following):

    Code:
    Private Declare Function GetFileTime Lib "kernel32.dll" _
    (ByVal hFile As Long, lpCreationTime As FILETIME, _
    lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
    
    Dim hFile As Variant  ' handle to the opened file
    Dim ctime As FILETIME  ' receives time of creation
    Dim atime As FILETIME  ' receives time of last access
    Dim mtime As FILETIME  ' receives time of last modification
    Dim thetime As SYSTEMTIME  ' used to manipulate the time
    Dim retval As Variant  ' return value
    
    Private Type FILETIME
      dwLowDateTime As Long
      dwHighDateTime As Long
    End Type
    
    Private Type SYSTEMTIME
      wYear As Integer
      wMonth As Integer
      wDayOfWeek As Integer
      wDay As Integer
      wHour As Integer
      wMinute As Integer
      wSecond As Integer
      wMilliseconds As Integer
    End Type
    
    Private Declare Function FileTimeToLocalFileTime Lib "kernel32.dll" (lpFileTime As _
    FILETIME, lpLocalFileTime As FILETIME) As Long
    
    Private Sub File1_Click()
        If File1.FileName <> "" Then
        hFile = File1.FileName 'file selected from file list box
        
        ' Next, get the creation, last-access, and last-modification times.
        retval = GetFileTime(hFile, ctime, atime, mtime)
        ' Convert the creation time to the local time zone.
        retval = FileTimeToLocalFileTime(ctime, ctime)
        ' Convert the FILETIME format to the SYSTEMTIME format.
        'retval = FileTimeToSystemTime(ctime, thetime)
        
        ' Display the date of creation of the file to the user.
        Text1.Text = "The file was created on " & thetime.wMonth & "-" & thetime.wDay & "-" & thetime.wYear
        End If
    End Sub
    Although I recieve an error at the "retval = GetFileTime(hFile, ctime, atime, mtime)" line, this is bloody close and I'm sure Kedaman or Megatron etc will point out the above anomolie to give you a proper example.

    [Edited by alex_read on 10-03-2000 at 05:41 AM]

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    put a listview
    dirlistbox and file list box on a form

    add 2 columns to the listview and set view as lvwReport
    check Full Row Select (if you're using vb6)

    set filelist as not visible


    Code:
    Option Explicit
    
    Private Sub Dir1_Change()
    File1.Path = Dir1.Path
    End Sub
    
    Private Sub File1_PathChange()
    Dim itmx As ListItem
    Dim i As Integer
    ListView1.ListItems.Clear
    
    For i = 0 To File1.ListCount - 1
      Set itmx = ListView1.ListItems.Add(, , File1.List(i))
      itmx.SubItems(1) = FileDateTime(File1.Path & "\" & File1.List(i))
    
    Next i
    
    
    End Sub
    
    
    Private Sub Form_Load()
    File1_PathChange
    End Sub
    Mark
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width