Solved

How to see file details in a FileListBox control

Posted on 2004-09-28
6
379 Views
Last Modified: 2013-12-26
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
Comment
Question by:bobski59
6 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12176316
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
 
LVL 2

Expert Comment

by:BlueScreen_
ID: 12176322
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12176366
See the sample code at this link as well:

http://vbnet.mvps.org/index.html?code/fileapi/fsoapicompare.htm
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:Dabas
ID: 12177008
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12177068
me too ;-)
0
 
LVL 12

Accepted Solution

by:
jkaios earned 250 total points
ID: 12206055
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now