如何在子目录中显示文件

时间:2017-03-06 16:35:56

标签: vb.net

我的文件夹结构如下:

  

ABC /测试/ TEST2

我想显示文件“test2”。

我没有收到错误,但执行后ListView为空。

以下是我的代码:

Private Sub listViewBtn_Click(sender As Object, e As EventArgs) Handles lvErrorBtn.Click
    Dim TempStr(2) As String
    Dim TempNode As ListViewItem
    Dim intCount As Integer = 0
    'Clear listview
    lvError.Clear()
    'Add columns to listview
    lvError.Columns.Add("File Name", 250)
    lvError.Columns.Add("Date Modified", 100)
    lvError.Columns.Add("File Size in KB", 100)

    'taking path from appconfig file
    Dim appValue As String = System.Configuration.ConfigurationManager.AppSettings("errors").ToString()
    'going to the directory
    Dim dirInfo As DirectoryInfo = New DirectoryInfo(appValue)
    Dim fsInfos() As FileInfo = dirInfo.GetFiles()
    Dim subdirs() As DirectoryInfo = dirInfo.GetDirectories()
    'iterating through subdir in directory
    For Each subdir As DirectoryInfo In subdirs
        'iterating through files in subdirectories
        For Each fsinfo As FileInfo In fsInfos
            If fromPDate.Value.Date <= fsinfo.LastAccessTime.Date Then
                TempStr(0) = fsinfo.ToString
                TempStr(1) = fsinfo.LastAccessTime
                TempStr(2) = Math.Round(fsinfo.Length / 1024)
                TempNode = New ListViewItem(TempStr)
                'add file to listview
                lvProcessed.Items.Add(TempNode)
                'count number of files in listview and display
                intCount += 1
                lvProcessedTxt.Text = intCount.ToString
            End If
        Next
    Next

0 个答案:

没有答案