|
楼主 |
发表于 2018-8-6 15:11
|
显示全部楼层
Sub mysearch2()
Dim Fso As New FileSystemObject
Dim str As String
Dim Filepath As String
Dim FileName As String
Dim fs, i, arr(1 To 10000)
Set fs = Application.FileSearch '设置一个搜索对象
Dim SearchPath As String
Dim FileFormat As String
Dim Findi As Integer
Dim objShell, objFolder, objFolderItem, MyFile$, brr(20000, 200), n&
Set objShell = CreateObject("shell.application")
FileFormat = Application.InputBox("请输入即将被操作的文件格式")
SearchPath = Application.InputBox("请输入目标路径,以\结尾", "提示")
With fs
.LookIn = SearchPath '设置搜索路径
.FileName = "*." & FileFormat '要搜索文件名和类型
.SearchSubFolders = True '是否需要搜索子文件 夹
If .Execute > 0 Then '如果找到文件
MsgBox "There were " & .FoundFiles.Count & " file(s) found." '显示找到多少个文件
For i = 1 To .FoundFiles.Count
FileName = Fso.GetFileName(.FoundFiles(i)) '获得文件名
Filepath = Fso.GetParentFolderName(.FoundFiles(i))
Range("B" & (i + 1)) = FileName
Range("A" & (i + 1)) = Filepath & "\" & FileName
'---------------------------------------------------------------------------------------------
objFolder = Filepath
MyFile = Dir(objFolder & "\*.mp4")
Set objFolder = objShell.Namespace(objFolder)
Do While MyFile <> ""
Set objFolderItem = objFolder.ParseName(MyFile)
If n = 0 Then
For k = 0 To UBound(brr, 2)
brr(0, k) = objFolder.GetDetailsOf(0, k)
n = 1
brr(n, 0) = MyFile
brr(n, k) = objFolder.GetDetailsOf(objFolderItem, k)
Next
Else
For k = 0 To UBound(brr, 2)
brr(n, 0) = MyFile
brr(n, k) = objFolder.GetDetailsOf(objFolderItem, k)
Next
End If
n = n + 1
MyFile = Dir
Loop
'-------------------------------------------------------------------------------------------------
Set objFolder = Nothing
Next i
Else
MsgBox "There were no files found."
End If
End With
Cells(1, 3).Resize(n + 1, UBound(brr, 2) + 1) = brr
MsgBox "完成"
End Sub
这是网上的代码自己进行拼接的,但是始终有问题,求各位大大帮忙 |
|