Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.1 KiB

  1. Attribute VB_Name = "HtmFileInfo"
  2. Option Explicit
  3. Private Const TITLE_START_C As String = "<TITLE>"
  4. Private Const TITLE_END_C As String = "</TITLE>"
  5. Private Const TITLE_LENGTH_C As Long = 7
  6. Private Const LOCCONTENT_START_C As String = "<META NAME=""DESCRIPTION"" LOCCONTENT="""
  7. Private Const LOCCONTENT_END_C As String = """>"
  8. Private Const LOCCONTENT_LENGTH_C As Long = 37
  9. Public Function GetHtmTitle( _
  10. ByVal i_strFileName As String _
  11. ) As String
  12. Dim FSO As Scripting.FileSystemObject
  13. Dim TS As Scripting.TextStream
  14. Dim strContents As String
  15. Dim strTitle As String
  16. Dim intTitleStart As Long
  17. Dim intTitleEnd As Long
  18. Set FSO = New Scripting.FileSystemObject
  19. Set TS = FSO.OpenTextFile(i_strFileName, ForReading)
  20. strContents = TS.ReadAll
  21. intTitleStart = InStr(1, strContents, TITLE_START_C, vbTextCompare)
  22. intTitleStart = intTitleStart + TITLE_LENGTH_C ' Skip the Title tag
  23. intTitleEnd = InStr(1, strContents, TITLE_END_C, vbTextCompare)
  24. If (intTitleEnd - intTitleStart > 0) Then
  25. strTitle = Mid$(strContents, intTitleStart, intTitleEnd - intTitleStart)
  26. GetHtmTitle = RemoveExtraSpaces(RemoveCRLF(strTitle))
  27. End If
  28. End Function
  29. Public Function GetHtmDescription( _
  30. ByVal i_strFileName As String _
  31. ) As String
  32. Dim FSO As Scripting.FileSystemObject
  33. Dim TS As Scripting.TextStream
  34. Dim strDesc As String
  35. Dim strContents As String
  36. Dim intDescStart As Long
  37. Dim intDescEnd As Long
  38. Set FSO = New Scripting.FileSystemObject
  39. Set TS = FSO.OpenTextFile(i_strFileName, ForReading)
  40. strContents = TS.ReadAll
  41. intDescStart = InStr(1, strContents, LOCCONTENT_START_C, vbTextCompare)
  42. If (intDescStart = 0) Then
  43. Exit Function
  44. End If
  45. intDescStart = intDescStart + LOCCONTENT_LENGTH_C ' Skip the tag
  46. intDescEnd = InStr(intDescStart, strContents, LOCCONTENT_END_C, vbTextCompare)
  47. If (intDescEnd - intDescStart > 0) Then
  48. strDesc = Mid$(strContents, intDescStart, intDescEnd - intDescStart)
  49. GetHtmDescription = RemoveExtraSpaces(RemoveCRLF(strDesc))
  50. End If
  51. End Function