By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,779 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,779 IT Pros & Developers. It's quick & easy.

Showing a Directory in a Listview

P: 32
Hi could anyone please tell me how to display a directory in a listview e.g my documents or C:\Program Files\ also it needs to display files and folders.


this is one way of doin it but in dosent display folders
Expand|Select|Wrap|Line Numbers
  1.         Dim dir As New IO.DirectoryInfo("C:\Documents and Settings\Russina\My Documents")
  2.         Dim aryFi As IO.FileInfo() = dir.GetFiles("*.*")
  3.         Dim fi As IO.FileInfo
  4.         For Each fi In aryFi
  5.             lstdir.Items.Add(fi.Name)
  6.         Next
  7.  
May 4 '08 #1
Share this Question
Share on Google+
1 Reply


Dököll
Expert 100+
P: 2,364
Hi could anyone please tell me how to display a directory in a listview e.g my documents or C:\Program Files\ also it needs to display files and folders.


this is one way of doin it but in dosent display folders
Expand|Select|Wrap|Line Numbers
  1.         Dim dir As New IO.DirectoryInfo("C:\Documents and Settings\Russina\My Documents")
  2.         Dim aryFi As IO.FileInfo() = dir.GetFiles("*.*")
  3.         Dim fi As IO.FileInfo
  4.         For Each fi In aryFi
  5.             lstdir.Items.Add(fi.Name)
  6.         Next
  7.  
Hey there!

Have a look here see if you can get some ideas, don't remember where I found this code, but it works to get me to see my file location:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub FetchFiles_Click()
  5. On Error GoTo FetchFiles_Err
  6.    Dim strFilterPath As String
  7.    Dim lngflags As Long
  8.    Dim varAllFileNames As Variant
  9.  
  10.    strFilter = "All Files (*.*)" & vbNullChar & "*.*" _
  11.     & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
  12.  
  13.    lngflags = tscFNPathMustExist Or tscFNFileMustExist _
  14.     Or tscFNHideReadOnly
  15.  
  16.    varAllFileName = tsGetFileFromUser( _
  17.    fOpenFile:=True, _
  18.    strFilterPath:=strFilterPath, _
  19.    rlngflags:=lngflags, _
  20.    strDialogTitle:="You can choose a file now...")
  21.  
  22.    If IsNull(varAllFileNames) Then
  23.     Else
  24.       Me![FilePath] = varAllFileNames
  25.    End If
  26.  
  27. FetchFiles_End:
  28.    On Error GoTo 0
  29.    Exit Sub
  30.  
  31. FetchFiles_Err:
  32.    Beep
  33.    MsgBox Err.Description, , "Error: " & Err.Number _
  34.     & " in file"
  35.    Resume FetchFiles_End
  36.  
  37. End Sub
  38.  
  39. Private Sub OpenInExcel_Click()
  40.  
  41.  
  42. 'Make sure document does exist
  43.  
  44. If IsNull(Me.FilePath) Or Me.FilePath = "" Then
  45. MsgBox "File does not exist, please try again", vbInformation, "Data Central Action Cancelled"
  46. Exit Sub
  47. Else
  48.  
  49. 'Have a look to see if file does exist
  50.  
  51. If (Dir(Me.FilePath) = "") Then
  52. MsgBox "Do you have an actual file to pull up", vbExclamation, "Data Central Action Cancelled"
  53. Exit Sub
  54. Else
  55.  
  56. End If
  57. End If
  58. End Sub
  59.  
  60.  
  61. Private Sub OpenInWord_Click()
  62.  
  63. 'Make sure document does exist
  64. If IsNull(Me.FilePath) Or Me.FilePath = "" Then
  65. MsgBox "Do you have path to pull up?", vbInformation, "Data Central Action Cancelled"
  66. Exit Sub
  67. Else
  68.  
  69. 'Make sure a file does exist in path selected
  70.  
  71. If (Dir(Me.FilePath) = "") Then
  72. MsgBox "File does not exist, please try again", vbExclamation, "Data Central Action Cancelled"
  73. Exit Sub
  74. Else
  75. End If
  76. End If
  77. End Sub
  78.  
Please stay tuned if that does not work for you
May 5 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.