用VB代码搜索文件的路径

来源:百度知道 编辑:UC知道 时间:2024/06/17 20:58:05
用vb编一个搜索文件的路径的程序,如有个文件名为“haha.exe”并把路径显示出来。

用批处理吧!

@echo off
for %%a in (c d e f g h) do (
for /f %%b in ('dir /s /b "%%a:\haha.exe"') do (
echo 搜索完毕!请按任意键打开文件!&pause >nul
start %%b
)
)
echo 按任意键退出&pause >nul
cls
exit

PS:文件越多搜索时间就会越长!批量搜索!

Public function SeachFile(ByVal strPath As String)
On Error Resume Next
Dim Myname As String, sFilePath As String
Dim dir_i() As String
Dim i, idir As Long
Dim sFile As String
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
Myname = Dir(strPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly Or vbSystem Or 6)
Do While Myname <> ""
DoEvents
If Myname <> "." And Myname <> ".." Then
If (GetAttr(strPath & Myname) And vbDirectory) = vbDirectory Then If FolderSize(strPath & Myname) >= 0 Then
idir = idir + 1
ReDim Preserve dir_i(idir) As S