|
Данный пример позволяет создать в одном
htm-файле ссылки на все htm-файлы, находящиеся в
одной директории
Расположите на форме элемент CommandButton и
элемент FileListBox. Option Explicit
Dim h, h1 As Integer
Private Sub Command1_Click()
StartIndex ("D:\vbcode") 'путь к папке индексации
файлов
End Sub
Public Function StartIndex(fPath As String)
h = 0
On Error GoTo ErrorHandler
File1.Path = fPath
Dim FileName As String 'имя файла для индекса
FileName = fPath & "\sharig.htm"
Dim fr
fr = FreeFile()
Open FileName For Output As #fr
Print #fr, "<html>"
Print #fr, "<head>"
Print #fr, "<title>Индексация файлов</title>"
Print #fr, "</head>"
Print #fr, "<body>"
Dim i As Integer
For i = 0 To File1.ListCount - 1
On Error Resume Next
Dim FNum As Integer
Dim txt As String
FNum = FreeFile
Open fPath & "\" & File1.List(i) For Input As #FNum
txt = Input(LOF(FNum), #FNum)
Close #FNum
Dim s() As String
Dim s1 As String
s = Split(txt, vbCrLf)
Dim d As Integer
d = 0
For h = 0 To UBound(s)
d = InStr(1, s(h), "<title>")
If d <> 0 Then Exit For
Next
If d = 0 Then
MsgBox "У файла --" & File1.List(i) & "-- нет
заголовка"
h = 1: s(h) = "<title>" & "Временный
заголовок" & "</title>": d = 1
End If
s1 = Mid(s(h), d + 7)
h = InStr(1, s1, "</title>")
s1 = Mid(s1, 1, h - 1)
Print #fr, "<p>" & "<a href=" & Chr(34) &
File1.List(i) & Chr(34) & ">" & s1 &
"</a></p>"
Next
Print #fr, "</body>"
Print #fr, "</html>"
Close #fr
StartIndex = FileName
Exit Function
ErrorHandler:
MsgBox FileName, , "Имя файла"
End Function
Public Function Splitting(s As String, s1 As String)
Dim ass() As String
Dim as1 As String
as1 = s
ass = Split(as1, s1)
Splitting = ass(1)
End Function
|
|