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

VB语句问题(VB高手请进!!!)

循环搜索电脑里的所有文件(VB语句)

 

 

VB高手请进!!!

追问:好是挺好的,但我想写蠕虫病毒,让它自动搜索。不方便请加本人QQ:615775923!

答案:窗体上有四个控件,命令按钮command1。列表框list1。驱动器列表Drive1。文件夹列表Dir1。
驱动器和文件夹列表是用来选择你想要搜索的文件夹。
程序运行时选中你想要搜索的文件夹,单击搜索按钮。该文件夹下面所有的文件及子文件夹里面的文件都列到列表框中。
将代码复制到窗体即可。代码如下:


Private Sub Command1_Click()
  List1.Clear
  sosuofile (Dir1.List(Dir1.ListIndex))
  MsgBox "搜索完毕!,共找到" + Str(List1.ListCount) + "条记录。", vbOKOnly + vbExclamation, "提示"
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Sub sosuofile(MyPath As String)
Dim Myname As String
Dim dir_i() As String
Dim i, idir As Long
If Right(MyPath, 1) <> "\" Then MyPath = MyPath + "\"
Myname = Dir(MyPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
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: List1.AddItem "" & MyPath & " " & Myname '把找到的文件显示到列表框中
      End If
   End If
   Myname = Dir  '搜索下一项
Loop
For i = 0 To idir - 1
    Call sosuofile(MyPath + dir_i(i))
Next i
ReDim dir_i(0) As String
End Sub

Private Sub Form_Load()
Command1.Caption = "搜索"
End Sub

 

 

 

---------------------转的----------------------如果需要修改 请追问 并把要修改的内容留下--------------

上一个:怎么在VB语言中给函数过程传递参数?
下一个:实现开机运行DLL里的指定函数vb6

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,