• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

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
0
rajender123
Asked:
rajender123
  • 4
  • 3
1 Solution
 
Ryan ChongCommented:
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)
0
 
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
0
 
Ryan ChongCommented:
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
0
 
Ryan ChongCommented:
try add this into your Form_Load() event:

ListView1.FullRowSelect = True
0
 
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
0
 
Ryan ChongCommented:
Are you using VB6 or VB.NET ?
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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