vb搜索到文件复制到另一个文件夹代码

来源:百度知道 编辑:UC知道 时间:2024/06/14 14:17:22
比如说搜索到jkl.exe 复制到C:\Documents and Settings\Administrator\「开始」菜单\程序\启动

搜索文件代码:
Public Sub SeachFile(ByVal strPath As String)
On Error Resume Next
Dim Fso As Object
Dim Fol As Object
Dim Fil As Object
Dim MyName As String

Set Fso = CreateObject("Scripting.FileSystemObject")
Set Fol = Fso.GetFolder(strPath)
If strPath <> "" Then
If Right(strPath, 1) = "\" Then
strPath = Left(strPath, Len(strPath) - 1)
End If
Label1.Caption = strPath
DoEvents
MyName = Dir(strPath & "\文件备份*.rar ") '这里改你想查找的文件名"
Do While MyName <> "" ' 开始循环。

If Len(MyName) > 0 Then
Text1.Text = Text1.Text & vbCrLf & strPath & "\" & MyName
Exit Do
End If
MyName = Dir()
Loop

End If

'扫描子目录
For Each Fol In Fol.SubFolders
SeachFile Fol
Next
End Sub