home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / Scan_all_F2146633112009.psc / MakeHTMLDir / Form1.frm < prev    next >
Text File  |  2009-03-11  |  18KB  |  483 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "MakeHTML-List v1.0.0"
  5.    ClientHeight    =   1695
  6.    ClientLeft      =   45
  7.    ClientTop       =   435
  8.    ClientWidth     =   6870
  9.    BeginProperty Font 
  10.       Name            =   "Courier New"
  11.       Size            =   8.25
  12.       Charset         =   0
  13.       Weight          =   400
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    Icon            =   "Form1.frx":0000
  19.    LinkTopic       =   "Form1"
  20.    LockControls    =   -1  'True
  21.    MaxButton       =   0   'False
  22.    ScaleHeight     =   1695
  23.    ScaleWidth      =   6870
  24.    StartUpPosition =   2  'CenterScreen
  25.    Begin VB.TextBox txtTotPapage 
  26.       Height          =   315
  27.       Left            =   3555
  28.       TabIndex        =   8
  29.       Text            =   "59"
  30.       Top             =   750
  31.       Width           =   420
  32.    End
  33.    Begin VB.CheckBox Check2 
  34.       Caption         =   "Create PDF File"
  35.       Height          =   270
  36.       Left            =   90
  37.       TabIndex        =   6
  38.       ToolTipText     =   "Only display the work"
  39.       Top             =   765
  40.       Value           =   1  'Checked
  41.       Width           =   2025
  42.    End
  43.    Begin VB.CheckBox Check1 
  44.       Caption         =   "Dispaly the work (Not recommended)..."
  45.       Height          =   270
  46.       Left            =   90
  47.       TabIndex        =   5
  48.       ToolTipText     =   "Only display the work"
  49.       Top             =   495
  50.       Value           =   1  'Checked
  51.       Width           =   4515
  52.    End
  53.    Begin VB.TextBox txtDir 
  54.       Height          =   285
  55.       Left            =   525
  56.       TabIndex        =   1
  57.       Text            =   "F:\Temp\Zero"
  58.       Top             =   105
  59.       Width           =   6225
  60.    End
  61.    Begin VB.CommandButton cmdScan 
  62.       Caption         =   "&Scan Directory"
  63.       Height          =   360
  64.       Left            =   4830
  65.       TabIndex        =   0
  66.       Top             =   450
  67.       Width           =   1920
  68.    End
  69.    Begin VB.Label Label2 
  70.       Caption         =   "Line x Page:"
  71.       Height          =   225
  72.       Left            =   2235
  73.       TabIndex        =   7
  74.       Top             =   795
  75.       Width           =   1320
  76.    End
  77.    Begin VB.Label lblFile 
  78.       Caption         =   "#"
  79.       Height          =   255
  80.       Left            =   90
  81.       TabIndex        =   4
  82.       Top             =   1380
  83.       Width           =   6690
  84.    End
  85.    Begin VB.Label lblPath 
  86.       Caption         =   "#"
  87.       Height          =   255
  88.       Left            =   90
  89.       TabIndex        =   3
  90.       Top             =   1080
  91.       Width           =   6690
  92.    End
  93.    Begin VB.Label Label1 
  94.       Caption         =   "Dir:"
  95.       Height          =   225
  96.       Left            =   45
  97.       TabIndex        =   2
  98.       Top             =   120
  99.       Width           =   480
  100.    End
  101. End
  102. Attribute VB_Name = "Form1"
  103. Attribute VB_GlobalNameSpace = False
  104. Attribute VB_Creatable = False
  105. Attribute VB_PredeclaredId = True
  106. Attribute VB_Exposed = False
  107. Option Explicit
  108.  
  109. ' .... Init PDF Class
  110. Private myPDF As New clsPDF
  111. Private totPDFPage As Integer
  112.  
  113. ' .... Limit Line for PDF Page
  114. Private strLine As Integer      ' .... Default = 59
  115.  
  116. ' .... STOP the recursive Scan Dir
  117. Private STOP_PRESSED As Boolean
  118.  
  119. ' .... to Strip a Dir
  120. Private Const gstrNULL$ = ""
  121. Private Const gstrSpace$ = " "
  122. Private Const gstrSEP_DIR$ = "\"
  123. Private Const gstrSEP_DIRALT$ = "/"
  124. Private Const gstrSEP_EXT$ = "."
  125. Private Const gstrCOLON$ = ":"
  126. Private Const gstrSwitchPrefix1 = "-"
  127. Private Const gstrSwitchPrefix2 = "/"
  128. Private Const gstrCOMMA$ = ","
  129.  
  130. ' .... Function Shell files
  131. Private Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  132.  
  133. ' .... Constant
  134. Private Const SW_SHOWNORMAL = 1
  135. Private Sub AddItem2Array1D(ByRef VarArray As Variant, ByVal VarValue As Variant)
  136.   Dim i  As Long
  137.   Dim iVarType As Integer
  138.   On Error Resume Next
  139.   DoEvents
  140.   iVarType = VarType(VarArray) - 8192
  141.   i = UBound(VarArray)
  142.   Select Case iVarType
  143.     Case vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbDecimal, vbByte
  144.       If VarArray(0) = 0 Then
  145.         i = 0
  146.       Else
  147.         i = i + 1
  148.       End If
  149.     Case vbDate
  150.       If VarArray(0) = "00:00:00" Then
  151.         i = 0
  152.       Else
  153.         i = i + 1
  154.       End If
  155.     Case vbString
  156.       If VarArray(0) = vbNullString Then
  157.         i = 0
  158.       Else
  159.         i = i + 1
  160.       End If
  161.     Case vbBoolean
  162.       If VarArray(0) = False Then
  163.         i = 0
  164.       Else
  165.         i = i + 1
  166.       End If
  167.     Case Else
  168.   End Select
  169.   ReDim Preserve VarArray(i)
  170.   VarArray(i) = VarValue
  171.   DoEvents
  172. End Sub
  173.  
  174. Private Function AllFilesInFolders(ByVal sFolderPath As String, Optional bWithSubFolders As _
  175.                                             Boolean = True, Optional strFlag As String = "*.*") As String()
  176.     Dim sTemp As String
  177.     Dim sDirIn As String
  178.     ReDim sFilelist(0) As String
  179.     ReDim sSubFolderList(0) As String
  180.     ReDim sToProcessFolderList(0) As String
  181.     Dim i As Integer, j As Integer
  182.     sDirIn = sFolderPath
  183.     If Not (Right$(sDirIn, 1) = "\") Then sDirIn = sDirIn & "\"
  184.     On Local Error Resume Next
  185.     sTemp = Dir$(sDirIn & strFlag)
  186.     Do While sTemp <> ""
  187.       AddItem2Array1D sFilelist(), sDirIn & sTemp
  188.       sTemp = Dir
  189.       DoEvents
  190.     Loop
  191.     If bWithSubFolders Then
  192.       sTemp = Dir$(sDirIn & strFlag, vbDirectory)
  193.       Do While sTemp <> ""
  194.       DoEvents
  195.          If sTemp <> "." And sTemp <> ".." Then
  196.             If (GetAttr(sDirIn & sTemp) And vbDirectory) = vbDirectory Then
  197.               AddItem2Array1D sToProcessFolderList, sDirIn & sTemp
  198.             End If
  199.          End If
  200.          sTemp = Dir
  201.          DoEvents
  202.          If STOP_PRESSED = True Then Exit Do
  203.       Loop
  204.       If UBound(sToProcessFolderList) > 0 Or UBound(sToProcessFolderList) = 0 And sToProcessFolderList(0) <> "" Then
  205.         For i = 0 To UBound(sToProcessFolderList)
  206.           DoEvents
  207.           sSubFolderList = AllFilesInFolders(sToProcessFolderList(i), bWithSubFolders)
  208.           If UBound(sSubFolderList) > 0 Or UBound(sSubFolderList) = 0 And sSubFolderList(0) <> "" Then
  209.             For j = 0 To UBound(sSubFolderList)
  210.               AddItem2Array1D sFilelist(), sSubFolderList(j)
  211.               DoEvents
  212.               If STOP_PRESSED = True Then Exit For
  213.             Next
  214.           End If
  215.           DoEvents
  216.           If STOP_PRESSED = True Then Exit For
  217.         Next
  218.       End If
  219.     End If
  220.     AllFilesInFolders = sFilelist
  221.     DoEvents
  222. Exit Function
  223. End Function
  224.  
  225. Private Sub ScanFolder(strPath As String, includeSubDirectory As Boolean, HTMLTitle As String, _
  226.                 Optional sTitleOfFile As String = "Dir_Scan", Optional fFlag As String = "*.*", Optional MakeAsPDFfile As Boolean = False)
  227.     ' .... Declarations Dirs and Files
  228.     Dim lFLCount As Long
  229.     Dim j As Integer
  230.     Dim fOlder As Integer
  231.     Dim totF As Integer
  232.     Dim sDirOld As String
  233.     Dim ix As Integer
  234.     
  235.     ' .... Declarations HTML
  236.     Dim FL As Integer
  237.     Dim i As Long
  238.     Dim X As Long
  239.     Dim strHead As String
  240.     Dim strList As String
  241.     Dim strBody As String
  242.     Dim strEnd As String
  243.     Dim strEndData As String
  244.     
  245.     Dim arrID() As Variant
  246.     Dim StrKey As String
  247.     
  248.     Dim strTip As String
  249.     Dim strTipFormatted As String
  250.     
  251.     Dim htmlFile As String
  252.     Dim PDFileName As String
  253.     
  254.     On Local Error GoTo ErrorHandler
  255.     
  256.     ReDim FileList(0) As String
  257.     
  258.     ix = 0
  259.     strLine = 0
  260.     
  261.     htmlFile = App.Path + "\" + App.Title + "_tmp.html"
  262.     PDFileName = App.Path + "\" + App.Title + ".pdf"
  263.     
  264.     ' .... Dispaly Info?
  265.     If Check1.Value = 1 Then
  266.         lblFile.Caption = "pre-analysis... please wait!"
  267.         lblPath.Caption = strPath
  268.     End If
  269.     
  270.     '.... Make the HTML Strings
  271.     strHead = "<html>"
  272.     strHead = strHead & "<head>"
  273.     strHead = strHead & "<meta http-equiv=""Content-Language"" content=""it"">"
  274.     strHead = strHead & "<meta http-equiv=""Content-Type"" content=""text/html; charset=""windows-1252"">"
  275.     strHead = strHead & "<meta name=""GENERATOR"" content="" & App.EXEName  & "">"
  276.     strHead = strHead & "<meta name=""ProgId"" content="" & App.EXEName & "".Editor.Document>"
  277.     
  278.     strHead = strHead & "<html><head><title>" & HTMLTitle & "</title></head>"
  279.     strHead = strHead & "<body link=#000080 vlink=#000080 alink=#000080>"
  280.     strHead = strHead & "<p align=center><b><font face=courier new size=2 color=#000080><u>"
  281.     strHead = strHead & "<a name=top></a>" & HTMLTitle & "</u></font><font color=#000080 face=courier new size=2><br></font></b>"
  282.     strHead = strHead & "<font color=#000080 face=courier new size=2>Result of Scan Folder: </font><b><font color=#FF0000 face=courier new size=2>"
  283.     strHead = strHead & strPath & "</font></b><br><br>"
  284.     strHead = strHead & "<div><font face=courier new size=2 color=#000080><table border=0 width=100% cellspacing=1 cellpadding=1>"
  285.     ' .... END ONE
  286.     
  287.     ' .... Start recursive Dirs and Files
  288.     FileList = AllFilesInFolders(strPath, includeSubDirectory, fFlag)
  289.     lFLCount = UBound(FileList)
  290.     
  291.     If MakeAsPDFfile Then
  292.         ' .... Make OutPut FileName as PDF File
  293.         myPDF.PaperSize = pdfA4
  294.         myPDF.FileName = PDFileName
  295.         myPDF.StartPDF
  296.         ' ....
  297.     End If
  298.         
  299.         For j = 0 To UBound(FileList)
  300.             If FileList(j) <> "" Then
  301.                 DoEvents
  302.                 ' .... Count Line for New PDF Page
  303.                 strLine = strLine + 1
  304.                 ' .... Write only one Dir
  305.                 If StripChar(FileList(j), "\") <> sDirOld Then
  306.                     fOlder = fOlder + 1
  307.                     ' .... Make the link of HTML
  308.                     strList = strList & "<tr><td bgcolor=#FFFFCC><b><a href=#" & fOlder & ">[#" & fOlder & "] " & StripChar(FileList(j), "\") & "</a></b></td></tr>"
  309.                     strBody = strBody & "<tr><td width=100% bgcolor=#000080><b><font color=#FFFFFF><a name=" & fOlder & "></a>" & fOlder & "-" & StripChar(FileList(j), "\") & "</font></b></td></tr>"
  310.                     strBody = strBody & "<tr><td width=100%><p align=right><a href=#top><font face=courier new color=#000080 size=1>Back to Top</font></a></td></tr>"
  311.                     
  312.                     strBody = strBody & "<tr><td width=100% bgcolor=#000080><b><font color=#FFFFFF><a name=#" & "[#" & fOlder & "] " & StripChar(FileList(j), "\") & "</a></font></b></td></tr>"
  313.                     strBody = strBody & "<tr><td width=100%><p align=right><a href=#" & "[#" & fOlder & "] " & StripChar(FileList(j), "\") & "><font face=courier new color=#000080 size=1>Back to Folder</font></a></td></tr>"
  314.                     
  315.                     strBody = strBody & "<tr><td width=100%><font face=courier new size=2>"
  316.                     
  317.                     ' .... Write PDF Line
  318.                     If MakeAsPDFfile Then
  319.                         myPDF.FontSize = 6
  320.                         Call MakeToPDFile("[#" & fOlder & "] " & StripChar(FileList(j), "\"), pdfBold)
  321.                     End If
  322.                     ' ....
  323.                     
  324.                     If Check1.Value = 1 Then lblPath.Caption = StripChar(FileList(j), "\")
  325.                 End If
  326.                 ix = ix + 1
  327.                 strBody = strBody & StripDirectory(FileList(j)) & "<span style=background-color:#FFFFCC><font color=#FF0000> " & ix & "</font></span><br>"
  328.                 sDirOld = StripChar(FileList(j), "\")
  329.                 
  330.                 ' .... Write PDF Line
  331.                 If MakeAsPDFfile Then
  332.                     myPDF.FontSize = 5
  333.                     Call MakeToPDFile(StripDirectory(FileList(j)) & " (" & ix & ")", pdfRegular)
  334.                 End If
  335.                 ' ....
  336.                 
  337.             End If
  338.             DoEvents
  339.             
  340.             ' .... Start New PDF Page
  341.             If strLine >= txtTotPapage.Text Then strLine = 0
  342.             
  343.             If Check1.Value = 1 Then lblFile.Caption = StripDirectory(FileList(j))
  344.             If STOP_PRESSED = True Then Exit For
  345.         Next
  346.                
  347.     '.... Write the List of Dir
  348.     strList = strList & "</table></div><p> </p><div><font face=courier new size=1><table border=0 cellpadding=1 cellspacing=1 width=100%>"
  349.     
  350.     ' .... Create the Final part with my personal Data
  351.     strEnd = "</tr></table></div><p> </p><p><font face=courier new size=1>E-mail: <a href=mailto:salvocortesiano@netshadows.it>Salvo Cortesiano</a><br>"
  352.     strEnd = strEnd & "On the web: <a href=http://www.netshadows.it/>http://www.netshadows.it/</a><br><br>"
  353.     strEnd = strEnd & "⌐ 2008-" & Format(Now, "mmmm, dd yyyy") & " by Salvo Cortesiano All Right Reserved.</a></font></p></body></html>"
  354.     
  355.     strEndData = "Total Folders: <font face=courier new color=#000080 size=1>" & fOlder & "<br></font>"
  356.     strEndData = strEndData & "Total Files: <font face=courier new color=#000080 size=1>" & ix & "<br></font>"
  357.     
  358.     If MakeAsPDFfile Then
  359.         myPDF.FontSize = 5
  360.         Call MakeToPDFile(" ", pdfRegular)
  361.         Call MakeToPDFile("⌐ 2008-" & Format(Now, "mmmm, dd yyyy") & " by Salvo Cortesiano All Right Reserved.", pdfBold)
  362.         Call MakeToPDFile("http://www.netshadows.it/", pdfBold)
  363.         Call MakeToPDFile("-------------------------", pdfRegular)
  364.         Call MakeToPDFile("Total Folders: " & fOlder, pdfBold)
  365.         Call MakeToPDFile("Total Files: " & ix, pdfBold)
  366.     End If
  367.     ' ....
  368.     
  369.     ' .... Write the HTML File
  370.     FL = FreeFile
  371.     Open App.Path + "\" + sTitleOfFile + ".html" For Output As FL
  372.     Print #FL, strHead;
  373.     Print #FL, strList;
  374.     Print #FL, strBody;
  375.     Print #FL, strEnd;
  376.     Print #FL, strEndData;
  377.     Close FL
  378.     
  379.     
  380.     ' .... Close the PDF File
  381.     If MakeAsPDFfile Then
  382.         myPDF.EndPDF
  383.         Set myPDF = Nothing
  384.     End If
  385.     ' .... Reset All
  386.     cmdScan.Caption = "&Scan Directory"
  387.     lblFile.Caption = "Total Files: " & ix
  388.     lblPath.Caption = "Total Folders: " & fOlder
  389.     
  390.     ' .... Open PDF FileName?
  391.     If MakeAsPDFfile Then
  392.         If Dir$(PDFileName) <> "" Then
  393.             If MsgBox("Fle PDF created! Number of Page: " & totPDFPage + 1 & vbCrLf & "Open the File PDF?", vbYesNo + vbInformation + vbDefaultButton1, "Open File") = vbYes Then
  394.                 ShellExecute 0&, vbNullString, PDFileName, vbNullString, App.Path, SW_SHOWNORMAL
  395.             End If
  396.         End If
  397.     End If
  398.     
  399.     ' .... Open FileName?
  400.      If Dir$(htmlFile) <> "" Then
  401.         If MsgBox("Open the File?", vbYesNo + vbInformation + vbDefaultButton1, "Open File") = vbYes Then
  402.                 ShellExecute 0&, vbNullString, htmlFile, vbNullString, App.Path, SW_SHOWNORMAL
  403.         End If
  404.     End If
  405.   Exit Sub
  406. ErrorHandler:
  407.         MsgBox "Error #" & Err.Number & "." & vbCrLf & Err.Description & vbCrLf & "Localizzato: {Sub=AllFileInFolder}", vbCritical, App.Title
  408.     Err.Clear
  409. End Sub
  410.  
  411. Private Function StripChar(rsFileName As String, strCaracter As String) As String
  412.   On Error Resume Next
  413.   Dim i As Integer
  414.   For i = Len(rsFileName) To 1 Step -1
  415.     If Mid(rsFileName, i, 1) = strCaracter Then
  416.       Exit For
  417.     End If
  418.   Next
  419.   StripChar = Mid(rsFileName, 1, i - 1)
  420. End Function
  421.  
  422. Private Function StripDirectory(strString As String) As String
  423.     Dim intPos As Integer
  424.     StripDirectory = gstrNULL
  425.     intPos = Len(strString)
  426.     Do While intPos > 0
  427.         Select Case Mid$(strString, intPos, 1)
  428.         Case gstrSEP_DIR
  429.                 StripDirectory = Mid$(strString, intPos + 1)
  430.             Exit Do
  431.         Case gstrSEP_DIR, gstrSEP_DIRALT
  432.                 StripDirectory = Mid$(strString, intPos + 1)
  433.             Exit Do
  434.         End Select
  435.         intPos = intPos - 1
  436.     Loop
  437. End Function
  438.  
  439. Private Sub Check2_Click()
  440.     If Check2.Value Then txtTotPapage.Enabled = True Else txtTotPapage.Enabled = False
  441. End Sub
  442.  
  443. Private Sub cmdScan_Click()
  444.     If cmdScan.Caption = "&Scan Directory" Then
  445.         If Check2.Value And txtTotPapage.Text > 59 Then
  446.                 MsgBox "To much line: " & txtTotPapage.Text & "." & vbCrLf & "Sintax: > 1; < 60", vbExclamation, App.Title
  447.                     txtTotPapage.SelStart = 0
  448.                     txtTotPapage.SelLength = 2
  449.                     txtTotPapage.SetFocus
  450.             Exit Sub
  451.         End If
  452.         cmdScan.Caption = "&Stop Scan"
  453.             STOP_PRESSED = False
  454.             Call ScanFolder(txtDir, True, App.Title, App.Title + "_tmp", "*.*", Check2.Value)
  455.     ElseIf cmdScan.Caption = "&Stop Scan" Then
  456.         If MsgBox("Stop the Scan?", vbYesNo + vbInformation + vbDefaultButton1, "Stop Scan") = vbYes Then
  457.                 STOP_PRESSED = True
  458.             cmdScan.Caption = "&Scan Directory"
  459.         End If
  460.     End If
  461. End Sub
  462.  
  463. Private Sub Form_Load()
  464. '    txtDir = App.Path
  465. End Sub
  466.  
  467.  
  468.  
  469. Private Sub MakeToPDFile(strString As String, Optional strFontType As pdfFont = pdfRegular)
  470.     On Local Error GoTo ErrorHandler
  471.     ' .... Write the Text
  472.     myPDF.WritePDF strString, True, strFontType
  473.     If strLine >= txtTotPapage.Text Then
  474.         myPDF.NewPage
  475.         strLine = 0
  476.         totPDFPage = totPDFPage + 1
  477.     End If
  478. Exit Sub
  479. ErrorHandler:
  480.     Err.Clear
  481. End Sub
  482.  
  483.