[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to see file details in a FileListBox control

Posted on 2004-09-28
6
Medium Priority
?
505 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 54

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 54

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 54

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

Independent Software Vendors: 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!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

831 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