Solved

How to see file details in a FileListBox control

Posted on 2004-09-28
6
366 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
Comment Utility
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_
Comment Utility
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
Comment Utility
See the sample code at this link as well:

http://vbnet.mvps.org/index.html?code/fileapi/fsoapicompare.htm
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 27

Expert Comment

by:Dabas
Comment Utility
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
Comment Utility
me too ;-)
0
 
LVL 12

Accepted Solution

by:
jkaios earned 250 total points
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now