• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 514
  • Last Modified:

How to see file details in a FileListBox control

I have a form with a FileListBox control on it (actually two of them). The only thing is the controls list only (not surprisingly)the names of the file and nothing else.
I would like to have something with the same functionality of the FileListBox but would also show (at least) the file size and the date/time. Like Windows Explorer, I guess, but without the icons or the file type since real estate is scarce on my form.
Any suggestion would be appreciated.

Thanks
0
bobski59
Asked:
bobski59
1 Solution
 
Ryan ChongCommented:
See:

http://vbnet.mvps.org/index.html?code/fileapi/filedatetime.htm

for file size, we can use FileLen function, like:

Debug.Print FileLen("C:\test.txt")

It will returns the file size by bytes

Hope this helps
0
 
BlueScreen_Commented:
try using a ListView control. it is much more evolved and offer you a lot more feature than the FileListBox. i neved used it myself but a lot of experts here do.
0
 
Ryan ChongCommented:
See the sample code at this link as well:

http://vbnet.mvps.org/index.html?code/fileapi/fsoapicompare.htm
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
DabasCommented:
Hi bobski59,
I agree with BlueScreen, (although ryancys' links probably are useful too!)
I use ListViews for quite a lot of my applications, and am very happy with its features.

Dabas
0
 
Ryan ChongCommented:
me too ;-)
0
 
jkaiosIT DirectorCommented:
bobski,
Try these codes using the ListView control. Make sure to use the Windows Common Controls 6.0, NOT 5.0
because version 5 doesn't have the "MultiSelect" property and also has different ProgID. For example, in the
ColumnClick() event, version 6 = ColumnHeader As "MSComctlLib.ColumnHeader", while
version 5.0 = ColumnHeader As "ComctlLib.ColumnHeader"

1. Add a new Form
2. Select "Microsoft Windows Common Controls 6.0" from Project->Components
3. Add a ListView control to the Form
4. Add a Command button
5. Copy and paste the following codes

----------------------[ Start of Codes ]---------------------------------------------------------------------------

Private Sub Command1_Click()

 On Error Resume Next
 
 Dim ii As Long
 Dim xx As String, c1, c2, c3
 Dim sPath As String
 
 With ListView
   .View = lvwReport                  '<-- Dont forget this one !!!
   .Sorted = False                      '<-- This is important for the "ColumnClick" event
   .ColumnHeaders.Clear            '<-- Clear previous column headers
   .ListItems.Clear                      '<-- Clear previous contents of list
   .LabelEdit = lvwManual           '<-- Do not allow editing first column data
   .MultiSelect = True                 '<-- Allow multiple selection
   ' Add the following new column headers.
   .ColumnHeaders.Add , , "Name", 1000               'Column 1
   .ColumnHeaders.Add , , "Size", 1000, 1              'Column 2, align-right
   .ColumnHeaders.Add , , "Date Modified", 1800    'Column 3
   .ColumnHeaders.Add , , "Description", 2100        'Column 4

   sPath = "C:\Windows\"         'Directory to list files [can be changed]

   xx = Dir(sPath & "*.*")         'Get the first file

   Do Until xx = ""
      DoEvents
      ii = ii + 1                           '<-- This is the Row counter
      c1 = FormatNumber(FileLen(sPath & xx), 0)
      c2 = FileDateTime(sPath & xx)
      Select Case UCase(Right(xx, 3))
         Case "TXT", "LOG", "PRN"
            c3 = "Text File"
         Case "EXE", "COM"
            c3 = "Application File"
         Case "DLL"
            c3 = "Application Extension"
         Case "OCX"
            c3 = "ActiveX Control"
         Case Else
            c3 = UCase(Right(xx, 3)) & " File"
      End Select
      .ListItems.Add ii, , xx                   'Column 1 - Name of file
      .ListItems(ii).SubItems(1) = c1     'Column 2 - Size of file in bytes
      .ListItems(ii).SubItems(2) = c2     'Column 3 - Date file last modified
      .ListItems(ii).SubItems(3) = c3     'Column 4 - Type/description of file
      xx = Dir()    '<-- Ge the next file
   Loop
 End With
 
 MsgBox "Total Files in " & sPath & " = " & ListView.ListItems.Count
 
End Sub

Private Sub ListView_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

 '***************************************
 ' This will sort the clicked column in ascending first, then
'  descending when it is clicked the second time.
 '***************************************
 Static iSortKey%
 
 ' Reverse the order, if this is the same col.
 If ColumnHeader.Index = iSortKey Then
   If ListView.SortOrder = lvwDescending Then
      ListView.SortOrder = lvwAscending
   Else
      ListView.SortOrder = lvwDescending
   End If
 Else
   ' Always sort A-Z when clicking a diff. column
   ListView.SortOrder = lvwAscending
 End If
 
 ' Get clicked column's index number.
 iSortKey = ColumnHeader.Index
 
 ' Set the sort key and sort the List
 ' based on the selected sorting order.
 ListView.SortKey = iSortKey - 1
 ListView.Sorted = True

End Sub

----------------------[ End of Codes ]---------------------------------------------------------------------------

I hope this will help.

JK
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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