Displat files, files path and size in list box

I have pdf files in my d:\test folder.

I want to display all the files,  size and the  path of files in list box....

Can i use list box or let me know if any other control can be used to display.................... in VB

additionally i want to display the   headers as  filename, Infolder and size..
how will i do in VB
rajender123Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
check and customize this sample:

FindFirstFile: Recursive File Search for Single or Multiple File Types
http://vbnet.mvps.org/code/fileapi/recursivefiles_minimal_multiple.htm

to get the file size, you can try use the FileLen function, like:

filelen(yourfilepath)
rajender123Author Commented:
No  this  does not help my problem...

I am using list box... and on the click of button i am able to  display the  file name... using this code


Dim oFs As New FileSystemObject
Dim sAns() As String
Dim oFolder As Folder
Dim oFile As File
Dim lElement As Long

Dim X, lngbytes, y

ReDim sAns(0) As String
If oFs.FolderExists(Text1.Text & "\") Then
    Set oFolder = oFs.GetFolder(Text1.Text & "\")
   For Each oFile In oFolder.files
      lElement = IIf(sAns(0) = "", 0, lElement + 1)
      ReDim Preserve sAns(lElement) As String
       sAns(lElement) = oFile.name

list1.additem (ofile.name)
Next

End If


but, i want that the  list box should have three cols:-

1) File name
2) File Path
3) Size

I know in list box we should  have always one data.. what if i use Datagrid or  msflex grid????

can i get the information in any other controls.. with the  names of the cols as  i have mentioned  and the  files from the folder......................in VB only

please let me know
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
You may try use a ListView Control instead, you can find the ListView cotnrol by adding M$ Windows Common Controls x.0 from Menu Project > Components (Ctrl + T).

then add code like below:

Private Sub Command1_Click()
    Dim oFs As New FileSystemObject
    Dim sAns() As String
    Dim oFolder As Folder
    Dim oFile As file
    Dim lElement As Long
   
    Dim X, lngbytes, y, I As Integer
   
   
    ReDim sAns(0) As String
    If oFs.FolderExists(Text1.Text & "\") Then
        Set oFolder = oFs.GetFolder(Text1.Text & "\")
        For Each oFile In oFolder.Files
            lElement = IIf(sAns(0) = "", 0, lElement + 1)
            ReDim Preserve sAns(lElement) As String
            sAns(lElement) = oFile.Name
            ' list1.AddItem (oFile.Name)
            I = ListView1.ListItems.Count + 1
            ListView1.ListItems.Add I, , oFile.Name
            ListView1.ListItems(I).SubItems(1) = oFile.ParentFolder
            ListView1.ListItems(I).SubItems(2) = oFile.Size
        Next
    End If
End Sub

Private Sub Form_Load()
    ListView1.ColumnHeaders.Add 1, , "File Name"
    ListView1.ColumnHeaders.Add 2, , "File Path"
    ListView1.ColumnHeaders.Add 3, , "Size"
    ListView1.View = lvwReport
    ListView1.LabelEdit = lvwManual
End Sub


hope this helps, cheers

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

rajender123Author Commented:
Yes.. thanks . ryan.. it works ...

But  when i click on file name... it will  only highlight file name.............

can  we highlight complete row ... say if i select   first file.... it will highlight the filepath and file size  also.................................

cant we highlight the complete   row in list view....


actually the client wants the complete  row to  be highlighted if the user selects any file.............................

Is there any othere way round for this.............in VB

please guys  help me in this
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try add this into your Form_Load() event:

ListView1.FullRowSelect = True
rajender123Author Commented:
No there is no property in List view  like this ..............................................

 This is not working...

Please let me know how will i do that......... or in case is there any other control in VB we can use


please lete me know asap
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
Are you using VB6 or VB.NET ?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.