?
Solved

VB6 Display directory content into a list box

Posted on 2007-03-28
5
Medium Priority
?
2,592 Views
Last Modified: 2010-08-05
I know this is a simple one, but I for some reason can not get through it. I am trying to list the contents of a directory in VB6. I am trying to list it on a list box in checkbox mode so that I can later delete any files that are check can some one help me with this. Thank you.
0
Comment
Question by:leotron
[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
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18811054
what contents? the files, the directories?
are you aware that VB comes with a filelistbox control, where all you need to do is put the path and the filter in.

instead of the checkbox, use the multiselect open.
0
 
LVL 1

Author Comment

by:leotron
ID: 18811091
The thing is that I am simply tring to make it as simple as possible for my end users. and I think that the check box method would be easier for them. and I would like to list all files inside a particular directory.  and have the files listed in a list box so that the end user simply clicks on the check mark and that's it.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18811112
assuming your listbox is called lstFiles, and is configured to checkbox display

lstFiles.Clear

strFile = Dir("YourFolder\")
while strFile <> empty
  lstFiles.Add strFile
  strFile = Dir
wend

0
 
LVL 12

Accepted Solution

by:
jkaios earned 2000 total points
ID: 18812118
>>  am trying to list it on a list box in checkbox mode so that I can later delete any files that are checked.
I believe that a standard VB6 ListBox control cannot easily accomplish this because the standard VB6 ListBox doesn't have the "check" property.

The more preferable way is to do this is to use the ListView control available in Microsoft Windows Common Control 6.0

1. Add Microsoft Windows Common Controls 6.0 (MSCOMCTL.OCX) to your project
2. Select the ListView from the Toolbox
3. Copy and paste the following code to the form

'===============================================================================
Option Explicit

Private Sub Form_Load()
   populateListView "C:\Temp"
End Sub

Private Sub populateListView(sPath As String)

   Dim oItem As MSComctlLib.ListItem
   Dim sFile As String
   
   With ListView1
      .View = lvwReport
      .Sorted = False
      .LabelEdit = lvwManual
      .FullRowSelect = True
      .Checkboxes = True
      .HideSelection = False
      '---------------------
      .ColumnHeaders.Clear
      .ListItems.Clear
      '---------------------
      .ColumnHeaders.Add , , "?", 300
      .ColumnHeaders.Add , , "File Name", 3000
      .ColumnHeaders.Add , , "File Size", 1000, lvwColumnRight
      .ColumnHeaders.Add , , "Date Modified", 2000
   End With
   
   If Right(sPath, 1) <> "\" Then
      sPath = sPath & "\"
   End If
   
   sFile = Dir(sPath & "*.*")
   
   Do Until (sFile = "")
      DoEvents
      Set oItem = ListView1.ListItems.Add
      oItem.Tag = sPath & sFile
      oItem.SubItems(1) = sFile
      oItem.SubItems(2) = FormatNumber(FileLen(sPath & sFile), 0)
      oItem.SubItems(3) = FileDateTime(sPath & sFile)
      sFile = Dir()
   Loop
   
   Me.Caption = ListView1.ListItems.Count & " files(s) found"
   
End Sub
'===============================================================================
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
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.
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…
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…
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

777 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