文件列表

Public Function Findfile(MyPath As String, Expand As String, MyList As ListBox)
Dim Myname As String
Dim dir_i() As String
Dim i, idir As Long
Dim str_FileNameList() As String
Dim date_CreatTime()  As Date
Dim count1 As Integer
Dim int_TotalFileNum As Integer
Dim fso As New FileSystemObject
Dim file_Treat As File

MyList.Clear
If Right(MyPath, 1) <> "\" Then MyPath = MyPath + "\"

Myname = Dir(MyPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
int_TotalFileNum = 0

Do While Myname <> ""
    If Myname <> "." And Myname <> ".." Then
        If (GetAttr(MyPath & Myname) And vbDirectory) = vbDirectory Then '如果找到的是目录
'        idir = idir + 1
'        ReDim Preserve dir_i(idir) As String
'        dir_i(idir - 1) = Myname
        Else
            If UCase(Right(Myname, 3)) = UCase(Expand) Then
    '                MyList.AddItem Replace(UCase(Myname), UCase("." & Expand), "")              '把找到的文件显示到列表框中
                    int_TotalFileNum = int_TotalFileNum + 1
                     ReDim Preserve str_FileNameList(int_TotalFileNum)
                    str_FileNameList(int_TotalFileNum) = Myname
            End If
        End If
    End If
    Myname = Dir '搜索下一项
Loop

If int_TotalFileNum > 0 Then
     ReDim Preserve date_CreatTime(int_TotalFileNum)
    For count1 = 1 To int_TotalFileNum
            Set file_Treat = fso.GetFile(MyPath & str_FileNameList(count1))
            date_CreatTime(count1) = file_Treat.DateCreated
    Next
     'OrderByCreatTime date_CreatTime(), str_FileNameList()   '按时间进行排序
     OrderByName str_FileNameList()
     For count1 = 1 To int_TotalFileNum
        MyList.AddItem Replace(UCase(str_FileNameList(count1)), UCase("." & Expand), "")
        'Debug.Print date_CreatTime(count1) & " : " & str_FileNameList(count1)
     Next
End If
End Function

 

Private Sub OrderByName(ByRef FileName() As String)
      Dim i As Integer
      Dim J As Integer
      Dim length As Integer
      Dim temp
      length = UBound(FileName)
      For i = 1 To length - 1
            For J = 2 To length - i + 1
                  If Val(FileName(J - 1)) > Val(FileName(J)) Then
                        temp = FileName(J - 1)
                        FileName(J - 1) = FileName(J)
                        FileName(J) = temp
                  End If
            Next
      Next
End Sub
Private Sub OrderByCreatTime(ByRef CreatTime() As Date, ByRef FileName() As String)
      Dim i As Integer
      Dim J As Integer
      Dim length As Integer
      Dim temp
      length = UBound(CreatTime)
      For i = 1 To length - 1
            For J = 2 To length - i + 1
                  If CreatTime(J - 1) < CreatTime(J) Then
                        temp = CreatTime(J - 1)
                        CreatTime(J - 1) = CreatTime(J)
                        CreatTime(J) = temp
                        temp = FileName(J - 1)
                        FileName(J - 1) = FileName(J)
                        FileName(J) = temp
                  End If
            Next
      Next
End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值