Showing a Directory in a Listview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BarryM
    New Member
    • Mar 2008
    • 32

    Showing a Directory in a Listview

    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
    Code:
            Dim dir As New IO.DirectoryInfo("C:\Documents and Settings\Russina\My Documents")
            Dim aryFi As IO.FileInfo() = dir.GetFiles("*.*")
            Dim fi As IO.FileInfo
            For Each fi In aryFi
                lstdir.Items.Add(fi.Name)
            Next
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by BarryM
    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
    [code=vb]
    Dim dir As New IO.DirectoryInf o("C:\Documen ts and Settings\Russin a\My Documents")
    Dim aryFi As IO.FileInfo() = dir.GetFiles("* .*")
    Dim fi As IO.FileInfo
    For Each fi In aryFi
    lstdir.Items.Ad d(fi.Name)
    Next
    [/code]
    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:

    [code=vb]
    Option Compare Database
    Option Explicit

    Private Sub FetchFiles_Clic k()
    On Error GoTo FetchFiles_Err
    Dim strFilterPath As String
    Dim lngflags As Long
    Dim varAllFileNames As Variant

    strFilter = "All Files (*.*)" & vbNullChar & "*.*" _
    & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"

    lngflags = tscFNPathMustEx ist Or tscFNFileMustEx ist _
    Or tscFNHideReadOn ly

    varAllFileName = tsGetFileFromUs er( _
    fOpenFile:=True , _
    strFilterPath:= strFilterPath, _
    rlngflags:=lngf lags, _
    strDialogTitle: ="You can choose a file now...")

    If IsNull(varAllFi leNames) Then
    Else
    Me![FilePath] = varAllFileNames
    End If

    FetchFiles_End:
    On Error GoTo 0
    Exit Sub

    FetchFiles_Err:
    Beep
    MsgBox Err.Description , , "Error: " & Err.Number _
    & " in file"
    Resume FetchFiles_End

    End Sub

    Private Sub OpenInExcel_Cli ck()


    'Make sure document does exist

    If IsNull(Me.FileP ath) Or Me.FilePath = "" Then
    MsgBox "File does not exist, please try again", vbInformation, "Data Central Action Cancelled"
    Exit Sub
    Else

    'Have a look to see if file does exist

    If (Dir(Me.FilePat h) = "") Then
    MsgBox "Do you have an actual file to pull up", vbExclamation, "Data Central Action Cancelled"
    Exit Sub
    Else

    End If
    End If
    End Sub


    Private Sub OpenInWord_Clic k()

    'Make sure document does exist
    If IsNull(Me.FileP ath) Or Me.FilePath = "" Then
    MsgBox "Do you have path to pull up?", vbInformation, "Data Central Action Cancelled"
    Exit Sub
    Else

    'Make sure a file does exist in path selected

    If (Dir(Me.FilePat h) = "") Then
    MsgBox "File does not exist, please try again", vbExclamation, "Data Central Action Cancelled"
    Exit Sub
    Else
    End If
    End If
    End Sub
    [/code]

    Please stay tuned if that does not work for you
    Last edited by Dököll; May 5 '08, 02:27 AM. Reason: code...

    Comment

    Working...