当前位置:编程学习 > VB >>

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

比如说搜索到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

Private Sub Command1_Click()
Text1.Text = ""
Call SeachFile("d:\\")
End Sub


TEXT里面已经显示了文件的路径,用filecopy把文件复制到你指定的文件夹里就行了
Public Function GetFileList(ByVal lyPath As String, ByVal lyFiliter As String) As String
Dim FileName As String
FileName = Dir(lyPath, vbArchive)
Do While FileName <> ""
If lyFiliter <> "" Then
If UCase(Right(FileName, Len(lyFiliter))) = UCase(lyFiliter) Then
If GetFileList = "" Then
GetFileList = FileName
Else
GetFileList = GetFileList

上一个:怎样把VC++代码转换成VB代码
下一个:易语言和vb比较,功能够强大吗?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,