We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Displat files, files path and size in list box

rajender123
rajender123 asked
on
Medium Priority
199 Views
Last Modified: 2010-05-01
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
Comment
Watch Question

Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT

Commented:
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)

Author

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
Software Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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 ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT

Commented:
try add this into your Form_Load() event:

ListView1.FullRowSelect = True

Author

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 ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT

Commented:
Are you using VB6 or VB.NET ?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.