|
楼主 |
发表于 2013-5-25 13:13
|
显示全部楼层
Public flist$(65535, 3), fc&, fs&, k&, s$
Sub FileList()
s = InputBox("Please input File's Ext type:", "Find Files", "xl")
If s = "" Then Exit Sub Else s = LCase(s) & "*"
pth = InputBox("Confirm FileFolder Path:", "Find Files", ThisWorkbook.Path)
k = 0: fc = 0: fs = 0: tms = Timer
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(pth)
t = 0
For Each f In fld.Files
n = InStrRev(f.Name, ".")
If n Then
x = LCase(Mid(f.Name, n + 1))
If x Like s Then
t = 1
flist(k, 0) = x
flist(k, 1) = f.Name
flist(k, 2) = fld.Name
flist(k, 3) = fld.Path
k = k + 1
End If
End If
Next
If t Then fs = fs + 1
fc = fc + 1
Call GetFolderFile(pth)
[a1].CurrentRegion.Offset(1) = ""
If k Then [a2].Resize(k, 4) = flist
[b1] = "Check " & fc & " SubFolders Get " & k & " Files from " & fs & " Folders."
MsgBox Format(Timer - tms, "0.000s")
End Sub
Function GetFolderFile(pth)
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(pth)
Set fsb = fld.SubFolders
For Each fd In fsb
t = 0
For Each f In fd.Files
n = InStrRev(f.Name, ".")
If n Then
x = LCase(Mid(f.Name, n + 1))
If x Like s Then
t = 1
flist(k, 0) = x
flist(k, 1) = f.Name
flist(k, 2) = fd.Name
flist(k, 3) = fd.Path
k = k + 1
End If
End If
Next
If t Then fs = fs + 1
fc = fc + 1: Call GetFolderFile(fd.Path)
Next
End Function |
|