回覆列表
  • 1 # 使用者6877557603071

    首先將檔案顯示做了區分:資料夾名稱顯示folderlist(),檔名稱顯示filelist():

    Private Function folderlist(pathname As String, treeflag As Integer) "treeflag:0列表 1樹形 2樹形展開

    "資料夾數和名稱

    Dim sf As String

    sf = Dir(pathname, vbDirectory) "獲取第一個目錄名

    foldernum = 0

    Do While sf <> ""

    " 跳過當前的目錄及上層目錄

    If sf <> "." And sf <> ".." Then

    If (GetAttr(pathname + sf) And vbDirectory) = vbDirectory Then

    If treeflag = 0 Then

    Text2 = Text2 & sf & vbCrLf " 如果它是一個目錄,將其名稱新增到列表

    ElseIf treeflag = 1 Then

    Text2 = Text2 & Treestr & sf & vbCrLf

    ElseIf treeflag = 2 Then "樹形展開的時候,需要了解子目錄,所以還需進行遞迴呼叫

    Text2 = Text2 & Treestr & sf & vbCrLf

    folderlist pathname + sf, treeflag

    filelist pathname + sf, treeflag

    End If

    foldernum = foldernum + 1 "統計資料夾數目

    End If

    End If

    sf = Dir() " 查詢下一個目錄

    Loop

    If treeflag = 0 Then

    If foldernum <> 0 Then

    Text2 = Text2 & vbCrLf & "======共有" & foldernum & "個資料夾======" & vbCrLf & vbCrLf

    Else

    Text2 = Text2 & "======無子目錄======" & vbCrLf & vbCrLf

    End If

    ElseIf foldernum <> 0 Then

    Text2 = Text2 & Nullstr & vbCrLf & Nullstr & vbCrLf

    End If

    End Function

    Private Function filelist(pathname As String, treeflag As Integer) "0列表 1樹形 2樹形展開

    "檔案數和名稱

    Dim a As String

    a = Dir(pathname & "/*.*")

    filenum = 0

    Do While a <> ""

    If treeflag = 0 Then

    Text2 = Text2 & a & vbCrLf

    Else

    Text2 = Text2 & Treestr & a & vbCrLf

    End If

    filenum = filenum + 1 "統計檔案數目

    a = Dir

    Loop

    If treeflag = 0 Then

    If filenum <> 0 Then

    Text2 = Text2 & "======共有" & filenum & "個檔案======"

    Else

    Text2 = Text2 & "======無檔案資訊======"

    End If

    End If

    End Function

  • 中秋節和大豐收的關聯?
  • 冬天要怎麼給自己勇氣起床?