Solved

VB6 Display directory content into a list box

Posted on 2007-03-28
5
2,589 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 500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

717 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