推荐资料自学网址:http://www.51zxw.net/study.asp?vip=10241777
Private Sub Command0_Click()
Dim rec As New ADODB.Recordset
Dim cn1 As New ADODB.Connection
Dim cm1 As New ADODB.Command
Set cn1 = CurrentProject.Connection
cm1.ActiveConnection = cn1
Dim arrylist(5000) As String
Dim b As String
Dim Sfile As String
Dim SS, Sname, Sdir As String
Dim j As Integer
Dim i, u As Integer
If Me.Text1 = "" Then
MsgBox "请先填写文件夹路径!", vbCritical, "提示"
Exit Sub
End If
j = 0
Sfile = Trim(Me.Text1)
b = Dir(Sfile & "\*.*", vbHidden Or vbNormal) ''寻找文件
If b = "" Then
MsgBox Sfile & "文件夹中不存在文件", vbInformation, "提示"
Exit Sub
Else
Do While b <> ""
j = j + 1
arrylist(j) = b
b = Dir()
Loop
End If
cm1.CommandText = "delete from [Z-文件名存放] where 1=1 "
cm1.Execute
For i = 1 To j ''循环出去文件路径
SS = arrylist(i)
Sdir = Sfile + "\" + arrylist(i) ''路径
If InStrRev(SS, ".") > 0 Then
Sname = Left(SS, InStr(SS, ".") - 1)
Else
Sname = SS
End If
cm1.CommandText = "insert into [Z-文件名存放] (文件名称,文件地址) values('" & Sname & "','" & Sdir & "') "
cm1.Execute
Next
End Sub
联系客服