?
Solved

How to see file details in a FileListBox control

Posted on 2004-09-28
6
Medium Priority
?
466 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 53

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 53

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 53

Expert Comment

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

Accepted Solution

by:
jkaios earned 1000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

765 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