发布网友 发布时间:2022-04-20 14:45
共5个回答
热心网友 时间:2023-09-16 05:11
已经完成,请留下E _ M _ A _I L或者用下面内容
1.建立一个窗体
2.放置一个文本框,用于输入索引路径,文本框命名为txtDirPath
3.放置一个按钮,用于开始索引,按钮命名为cmdSearch
4.放置一个Label,用于显示索引进度,命名为lblState
5.放置一个Command按钮,用于保存索引结果,命名为cmdSave
程序代码如下:
Dim searchingPath As String
Dim pl As Long
Dim finalOut As String
Dim c As Long
Private Sub cmdSave_Click()
Open "c:\out.txt" For Output As #1
Print #1, finalOut
Close #1
lblState.Caption = "保存完成! 已经写入到C:\Out.txt": DoEvents
End Sub
Private Sub cmdSearch_Click()
c = 0
If Right(txtDirPath.Text, 1) <> "\" Then txtDirPath.Text = txtDirPath.Text + "\"
pl = Len(txtDirPath.Text)
SearchFile txtDirPath.Text
End Sub
Private Sub Form_Load()
Me.Show
txtDirPath.SetFocus
txtDirPath.SelStart = Len(txtDirPath.Text)
End Sub
Private Sub txtDirPath_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then cmdSearch_Click
End Sub
Sub SearchFile(strPath As String)
On Error Resume Next
Dim strName As String
Dim dir_i() As String
Dim i As Long, idir As Long
Dim showStr As String
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
strName = Dir(strPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
Do While Len(strName) > 0
If strName <> "." And strName <> ".." Then
If (GetAttr(strPath & strName) And vbDirectory) = vbDirectory Then
idir = idir + 1
ReDim Preserve dir_i(idir) As String
dir_i(idir - 1) = strName
Else
c = c + 1
showStr = Replace(Mid(strPath, pl + 1), "\", "><")
finalOut = finalOut + "<" + Left(showStr, Len(showStr) - 1) + strName + vbCrLf
End If
End If
strName = Dir
If searchingPath <> strPath Then
lblState.Caption = "索引数: " & CStr(c) & ",搜索目录: " & strPath
searchingPath = strPath
DoEvents
End If
Loop
For i = 0 To idir - 1
Call SearchFile(strPath + dir_i(i))
Next i
Erase dir_i
lblState.Caption = "搜索完成,总计文件数: " & CStr(c)
End Sub
热心网友 时间:2023-09-16 05:12
你前面的说的是什么意思啊,既然知道完全路径了,还要选什么文件啊,文件不就在完全路径中吗……
不过,要选定文件用Microsoft Common Dialog control控件还是很好的,根据你的要求:
Private Sub Command1_Click()
CommonDialog1.ShowOpen
name = CommonDialog1.FileName
End Sub
热心网友 时间:2023-09-16 05:12
用file控件,先把text1赋值给控件,然后调用file.path
热心网友 时间:2023-09-16 05:13
从部件中引用Microsoft Common Dialog control,试试这个控件,来解决你所谓“VB 选取文件夹内文件的文件名 ”
示例代码:
Private Sub Command1_Click()
CommonDialog1.ShowOpen
MsgBox CommonDialog1.FileName
End Sub
热心网友 时间:2023-09-16 05:13
将这个文件的文件名赋值给"name"项~~
这句话是什么意思???还有,你保存在text1中的路径指向的是一个文件夹还特定的文件(txt or 其它??)