在哪儿可以搜计算机VB编程,查找文件如何用VB来查找计算机的某个文件. 爱问知识人...

'提供一个运用递归查找文件的例子,查询目录和类型可以重新设计一下。VB窗口中,添加一个Commandbutton和List控件。

Private Sub Command1_Click()

List1。Clear

ntx = 0

Call GetDirPath("c:\windows\", "*。

com")

End Sub

Private Sub GetDirPath(CurrentPath As String, ByVal SearFile As String)

Dim nI As Integer, nDirectory As Integer, i As Long

Dim sFileName As String, sDirectoryList() As String

'在当前目录下,首先得到第1个文件

sFileName = Dir(CurrentPath, vbHidden Or vbDirectory Or vbReadOnly Or vbSystem)

Do While sFileName <> ""

If UCase(sFileName) Like UCase(SearFile) Then

i = GetAttr(CurrentPath + sFileName)

If (i And vbDirectory) = 0 Then

List1。

AddItem (CurrentPath + sFileName)

End If

End If

If sFileName <> "。" And sFileName <> "。。

" Then

'忽略非目录

If GetAttr(CurrentPath & sFileName) And vbDirectory Then

nDirectory = nDirectory + 1

ReDim Preserve sDirectoryList(nDirectory)

sDirectoryList(nDirectory) = CurrentPath & sFileName

End If

End If

sFileName = Dir

Loop

'递归调用

For nI = 1 To nDirectory

GetDirPath sDirectoryList(nI) & "\", SearFile

Next nI

End Sub

全部

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值