Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2606
  • Last Modified:

VB6 Display directory content into a list box

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
leotron
Asked:
leotron
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
leotronAuthor Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
jkaiosCommented:
>>  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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now