Simple file search hta

Author Message
SilentBob

  • Total Posts : 38
  • Scores: 0
  • Reward points : 0
  • Joined: 3/28/2007
  • Status: offline
Simple file search hta Friday, March 30, 2007 7:05 PM (permalink)
0
Hi,

Here's a simple hta I put together with a little help from some forum members here .
It just searches for the same string as you give it, but that was enough for me.
Could most likely be improved, but that's up to you.

 <html>
 <head>
 <title>File Search</title>
 <HTA:APPLICATION
  Application ID = "SearchFiles"
  APPLICATIONNAME = "File Search"
  BORDER = "dialog"
  BORDERSTYLE = "normal"
  CAPTION = "Yes"
  CONTEXTMENU = "Yes"
  ICON = ""
  INNERBORDER = "yes"
  MAXIMIZEBUTTON = "yes"
  MINIMIZEBUTTON = "yes"
  NAVIGABLE = "no"
  SCROLL = "auto"
  SCROLLFLAT = "no"
  SELECTION = "No"
  SHOWINTASKBAR = "Yes"
  SINGLEINSTANCE = "No"
  SYSMENU = "yes"
  VERSION = "1.0"
  WINDOWSTATE = "Normal"
  />
 </head>
 <style type="text/css">
     a:link {color: #F19105;}
     a:visited {color: #F19105;}
     a:active {color: #F19105;}
     a:hover {color: #FF9900;background-color: rgb(255, 255, 255);}
 </style>
 <SCRIPT Language="VBScript">
 Dim strInput
 Dim objFolderSearching
 Dim strHTML
 Dim strFilePath
 Dim strFileSize
 Dim strFileType
 Dim strFileModified
 Dim strFileAcces
 Dim strFileName
 Dim strSearchpath
 Dim strBrowsePath
 Dim iTimer
 
 Sub BrowseForFolder
    Dim objShell
    Dim objFolder
    Dim objFolderItem
    Const WINDOW_HANDLE = 0
    Const NO_OPTIONS = 0
    
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, "Choose map:",NO_OPTIONS)
    
    If objFolder Is Nothing Then Exit Sub
    
    Set objFolderItem = objFolder.Self
    strBrowsePath=CStr(objFolderItem.Path)
    txtPath.value = strBrowsePath
 End Sub
 
 Sub start
 
   strInput = txtSearch.value
    If strInput = "" Then
     DataArea.InnerHTML = "Nothing to do."
     Exit Sub
    End If
    
    DataArea.InnerHTML = "Busy searching..."
    iTimer = window.setInterval("Search", 1) 'wait 1 millisecond seconds just to get the message across :-)
 End Sub
 
 Sub Search
    Dim objFSO
 
    strSearchpath = txtPath.value
    Set objFSO = CreateObject("scripting.filesystemobject")
     
     if objFSO.FolderExists(strSearchpath) = True then
         Set objTeDoorZoekenFolder = objFSO.GetFolder(strSearchpath)
     else
         msgbox "Path not found. " & vbCrLf & strSearchpath,vbExclamation,"Path"
         DataArea.InnerHTML = "Try again."
         Set objFSO = Nothing
         txtPath.Select
         window.clearinterval(iTimer)
         Exit Sub
     end if
     Set objFolderSearching = objFSO.GetFolder(strSearchpath)
 
    strHTML = "Results: <br><br>"
    strHTML = strHTML & "<table border='1' style='border-collapse: collapse; font size:9pt' bordercolor='#CCCCCC' width='100%' id='Table1'>"
    strHTML = strHTML & "<tr>"
    strHTML = strHTML & "<td><strong>Name</strong></td>"
    strHTML = strHTML & "<td><strong>Path</strong></td>"
    strHTML = strHTML & "<td><strong>Size</strong></td>"
    strHTML = strHTML & "<td><strong>Type</strong></td>"
    strHTML = strHTML & "<td><strong>Modified</strong></td>"
    strHTML = strHTML & "<td><strong>Accessed</strong></td>"
    strHTML = strHTML & "</tr>"
 
    CheckFolder objFolderSearching
 
    strHTML = strHTML & "</table>"
    DataArea.InnerHTML = strHTML
    
    'release some memory
    window.clearinterval(iTimer)
    txtSearch.select
    strFilePath = ""
    strFileSize = ""
    strFileType = ""
    strFileAcces = ""
    strFileName = ""
    strHTML = ""
    strInput = ""
    Set objFSO = Nothing
    Set objFolderSearching = Nothing
 End Sub
 
 Sub CheckFolder(objCurrentFolder)
    Dim strTemp
    Dim strSearch
    Dim strOutput
    Dim objNewFolder
    Dim objFile
    Dim objStream
    Dim strCurrentFolder
 
    strSearch = UCase(strInput)
    On Error Resume Next
    For Each objFile In objCurrentFolder.Files
        strTemp = UCase(CStr(objFile.Name))
        If InStr(1, strTemp, strSearch, 1) <> 0 Then
            'Got one
            strFileName = CStr(objFile.Name)
            strFilePath = Cstr(objFile.ParentFolder)
            strFileSize = FormatNumber((objFile.Size/1000),2) + " Kb"
            strFileType = CStr(objFile.Type)
            strFileModified = CStr(objFile.DateLastModified)
            strFileAcces = CStr(objFile.DateLastAccessed)
 
            strHTML = strHTML & "<tr>"
            strHTML = strHTML & "<td>" & strFileName & "</td>"
            strHTML = strHTML & "<td><a href='" & strFilePath & "'>" & strFilePath & "</a></td>"
            strHTML = strHTML & "<td>" & strFileSize & "</td>"
            strHTML = strHTML & "<td>" & strFileType & "</td>"
            strHTML = strHTML & "<td>" & strFileModified & "</td>"
            strHTML = strHTML & "<td>" & strFileAcces & "</td>"
            strHTML = strHTML & "</tr>"
        End If
    Next
    'Recurse through all of the folders
    For Each objNewFolder In objCurrentFolder.subFolders
        CheckFolder objNewFolder
    Next
    On Error GoTo 0
    Set objCurrentFolder = Nothing
    Set objNewFolder = Nothing
    Set objFile = Nothing
    strTemp = ""
    strSearch = ""
 End Sub
 
 Sub StartOnEnter
     If window.event.keyCode = 13 Then
         Start
     End If
 End Sub
 
 </SCRIPT>
 <body onKeyPress="StartOnEnter" STYLE="overflow:auto;font:arial; color:#000000; filter:progid:DXImageTransform.Microsoft.Gradient (GradientType=0, StartColorStr='#FFFFFF', EndColorStr='#CCCCCC')">
 <BASEFONT SIZE="2">
 Search for:<BR>
 <input type="text" style="background-color:#ffffff" size="40" name="txtSearch" value="">
 in&nbsp
 <input type="text" style="background-color:#ffffff" size="25" name="txtPath" value="C:">
 <input id=runbutton class="button" type="button" value=" ... " name="brows_button"  onClick="BrowseForFolder"><p>
 <input id=runbutton STYLE="filter:progid:DXImageTransform.Microsoft.Gradient (GradientType=1, StartColorStr='#0575F1', EndColorStr='#A4C8EF')" class="button" type="button" value=" Go " name="run_button"  onClick="Start"><p>
 
 <span id="DataArea"></span>
 </BASEFONT>
 </body>
 </html>
 
 


Enjoy
 
#1
    dm_4ever

    • Total Posts : 3687
    • Scores: 82
    • Reward points : 0
    • Joined: 6/29/2006
    • Location: Orange County, California
    • Status: offline
    RE: Simple file search hta Saturday, March 31, 2007 4:23 PM (permalink)
    0
    Did a little cleanup and added a few comments.

    Updated:
    4/1/07 - Corrected the mistake pointed out in the post below this one
    4/1/07 - Added File Count
                             

     <html>
     <head>
     <title>File Search</title>
     <HTA:APPLICATION
     Application ID = "SearchFiles"
     APPLICATIONNAME = "File Search"
     BORDER = "Dialog"
     BORDERSTYLE = "Normal"
     CAPTION = "Yes"
     CONTEXTMENU = "Yes"
     ICON = ""
     INNERBORDER = "Yes"
     MAXIMIZEBUTTON = "Yes"
     MINIMIZEBUTTON = "Yes"
     NAVIGABLE = "No"
     SCROLL = "Auto"
     SCROLLFLAT = "No"
     SELECTION = "No"
     SHOWINTASKBAR = "Yes"
     SINGLEINSTANCE = "No"
     SYSMENU = "Yes"
     VERSION = "1.0"
     WINDOWSTATE = "Normal"
     />
     </head>
     <style type="text/css">
        a:link {color: #F19105;}
        a:visited {color: #F19105;}
        a:active {color: #F19105;}
        a:hover {color: #FF9900;background-color: rgb(255, 255, 255);}
     </style>
     <script Language="VBScript">
     Option Explicit
     
     Dim iTimer
     
     Sub BrowseForFolder
        Dim objShell, objFolder, objFolderItem, strBrowsePath
        
        ' define constants for Shell.Application object
        Const WINDOW_HANDLE = 0
        Const NO_OPTIONS = 0
        
        Set objShell = CreateObject("Shell.Application") ' Create Shell.Application object
        Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, "Choose map:",NO_OPTIONS) ' open file browser
        If objFolder Is Nothing Then Exit Sub
        Set objFolderItem = objFolder.Self     
        strBrowsePath = CStr(objFolderItem.Path) ' assign path retrieved
        txtPath.value = strBrowsePath ' copy path to input box
     End Sub
     
     Sub start
        Dim strInput  :  strInput = txtSearch.value
        
        If strInput = "" Then
            DataArea.InnerHTML = "Nothing to do."
            Exit Sub ' exit sub if no keyword is specified
        Else
            DataArea.InnerHTML = "Busy searching..." ' update HTML body with message
            iTimer = window.setInterval("Search", 1000) 'wait 1 second to ensure message is displayed
        End If
     End Sub
     
     Sub Search
        Dim objFSO, strSearchpath, objFolderSearching, strHTML, intCount
        
        intCount = 0
        window.clearInterval(iTimer) ' clear iTimer
        strSearchpath = txtPath.value ' get value from input box
        
        Set objFSO = CreateObject("scripting.filesystemobject") ' create filesystemobject
        If objFSO.FolderExists(strSearchpath) = True Then
            Set objFolderSearching = objFSO.GetFolder(strSearchpath) ' get folder if it exists
        Else
            ' give error if path is invalid and exit sub
            MsgBox "Path not found. " & vbCrLf & strSearchpath,vbExclamation,"Path"
            DataArea.InnerHTML = "Try again."
            Set objFSO = Nothing
            txtPath.Select
            Exit Sub
        End If
        
        ' begin building table with results
        strHTML = "Results [[COUNT] File(s) Found]: <br><br>" & _
                  "<table border='1' style='border-collapse: collapse; font size:9pt' bordercolor='#CCCCCC' width='100%' id='Table1'>" & _
                  "<tr><td><strong>Name</strong></td><td><strong>Path</strong></td>" & _
                  "<td><strong>Size</strong></td><td><strong>Type</strong></td>" & _
                  "<td><strong>Modified</strong></td><td><strong>Accessed</strong></td></tr>" 
        CheckFolder objFolderSearching, strHTML, intCount
        strHTML = strHTML & "</table>" ' call CheckFolder Function to continue building table w/ file(s) data
        strHTML = Replace(strHTML, "[COUNT]", intCount)    
        DataArea.InnerHTML = strHTML ' display table
        txtSearch.select
        Set objFSO = Nothing
        Set objFolderSearching = Nothing
     End Sub
     
     Sub CheckFolder(objCurrentFolder, ByRef strHTML, ByRef intCount) 
        Dim strSearch, objFile, strTemp, strFileName, strFilePath, strFileSize
        Dim strFileType, strFileModified, strFileAccess, objNewFolder
        
        strSearch = UCase(txtSearch.value) ' get value from input box
     
        For Each objFile In objCurrentFolder.Files ' get files in folder
            On Error Resume Next
            strTemp = UCase(CStr(objFile.Name))
            If InStr(1, strTemp, strSearch, 1) <> 0 Then ' if file name matches keyword then build table
                'Got one
                intCount = intCount + 1
                strFileName = objFile.Name
                strFilePath = objFile.ParentFolder
                strFileSize = FormatNumber((objFile.Size/1024),2) + " Kb"
                strFileType = objFile.Type
                strFileModified = objFile.DateLastModified
                strFileAccess = objFile.DateLastAccessed
                
                strHTML = strHTML & "<tr><td>" & strFileName & "</td><td><a href='" & strFilePath & "'>" & _
                                    strFilePath & "</a></td><td>" & strFileSize & "</td>" & _
                                    "<td>" & strFileType & "</td><td>" & strFileModified & "</td>" & _
                                    "<td>" & strFileAccess & "</td></tr>"
            End If
            On Error GoTo 0
        Next
        
        For Each objNewFolder In objCurrentFolder.subFolders ' get subfolders for recursion
            On Error Resume Next
            CheckFolder objNewFolder, strHTML, intCount
            On Error GoTo 0
        Next
     End Sub
     
     Sub StartOnEnter
        If window.event.keyCode = 13 Then ' if the Enter key is pressed, then call the Start sub
            Start
        End If
     End Sub
     
     </script>
     <body onKeyPress="StartOnEnter" STYLE="overflow:auto;font:arial; color:#000000; filter:progid:DXImageTransform.Microsoft.Gradient (GradientType=0, StartColorStr='#FFFFFF', EndColorStr='#CCCCCC')">
     <basefont SIZE="2">
     Search for:<BR>
     <input type="text" style="background-color:#ffffff" size="40" name="txtSearch" value="">
     in&nbsp
     <input type="text" style="background-color:#ffffff" size="25" name="txtPath" value="C:\">
     <input id=runbutton class="button" type="button" value=" ... " name="brows_button"  onClick="BrowseForFolder"><p>
     <input id=runbutton STYLE="filter:progid:DXImageTransform.Microsoft.Gradient (GradientType=1, StartColorStr='#0575F1', EndColorStr='#A4C8EF')" class="button" type="button" value=" Go " name="run_button"  onClick="Start"><p>
     <span id="DataArea"></span>
     </basefont>
     </body>
     </html>
     
    <message edited by dm_4ever on Monday, April 02, 2007 2:49 AM>
    dm_4ever

    My philosophy: K.I.S.S - Keep It Simple Stupid
    Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
    Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      SilentBob

      • Total Posts : 38
      • Scores: 0
      • Reward points : 0
      • Joined: 3/28/2007
      • Status: offline
      RE: Simple file search hta Sunday, April 01, 2007 7:31 AM (permalink)
      0
      And nobody noticed my huge ameture blunder? [sm=tongue.gif]
      This
               strFileSize = FormatNumber((objFile.Size/1000),2) + " Kb"

      Should be this
               strFileSize = FormatNumber((objFile.Size/1024),2) + " Kb"

       
      #3
        psebast1

        • Total Posts : 1
        • Scores: 0
        • Reward points : 0
        • Joined: 4/1/2007
        • Status: offline
        RE: Simple file search hta Sunday, April 01, 2007 11:12 AM (permalink)
        0
        hi can anyone help me to create any simple game in vbscript? please?
         
        #4
          SilentBob

          • Total Posts : 38
          • Scores: 0
          • Reward points : 0
          • Joined: 3/28/2007
          • Status: offline
          RE: Simple file search hta Monday, April 02, 2007 1:03 AM (permalink)
          0
          I think you'd better post such questions at WSH & Client Side VBScript
          And give some more info on what kind of game you're thinking of .
          Just of the top of a google result: a blackjack game

           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9