1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2013
    Roanoke, VA
    Rep Power

    Search files in a folder

    Hi, does anyone know how to search files in a folder using asp?

    My work project is to select a .mpg file from a dropdown menu which lists all the files in that folder. Once the file is selected it will play in a media player. If that is a clip the person wants, he/she then clicks a button to copy the file to a folder. All of this works in testing.

    However, I want to add a search box that will allow the person to search the files in the folder.

    If the files are:

    I want the person to be able to type tre and the files tree.mpg and tree-1.mpg are the only files displayed - instead of all the files in the folder.

    I have searched in google, bing, and this forum and can not find any code or information that has helped. I was surprised at how few returns came back.

    I have been tweaking asp stuff for a few years now and this is my first time to post a question. I am really stuck on this one.

    Thanks in advance. I really appreciate it.
  2. #2
  3. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2013
    Roanoke, VA
    Rep Power
    I have finally found some code that I may be able to use for this. I will need to see if I can tweak the results to feed a dropdown menu. I found a "possible" solution here. Now back to tweaking. Still appreciate any thoughts on this. Thanks!
    ASP File Finder by Blowno
  4. #3
  5. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Columbus, OH
    Rep Power
    Are you want to reload your dropdown menu when use type on search box or you displaying file names in the list? How you displaying files from that folder? Is each user has own folder? It looks like you expect has copy of original file for each user. Are you using database to track user activity? We need to know more details and publish your code for page with search box
    __________________________________________________ _____
    if you found this post is useful click Give Rep button (bottom side on this reply ) and agree
  6. #4
  7. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2013
    Roanoke, VA
    Rep Power
    Thanks for the response gk53. I found a link that got me what I needed. http://http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6346&lngWId=4

    I tried to post this the other day but it went to a moderator....unsure why. I wanted to provide the link for anyone looking for the same thing. In my case, this worked great but some of the folders have so many files that it was taking too long for a search. Now, I am doing the same thing but I am writing the file names to a database and searching the database. That way we only have to "build the database" as needed.

    Here is what worked for me (the non database version). It was just too slow on folders with a lot of files.

    <script type="text/javascript">
    function PlayIt(what){
    document.getElementById('video').innerHTML='<object width="300" height="300" '
    +'classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" '
    +'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" '
    +'standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">'
    +'<param name="url" value="'+what+'">'
    +'<param name="uiMode" value="full">'
    +'<param name="autoStart" value="true">'
    +'<param name="loop" value="true">'
    +'<embed type="application/x-mplayer2" '
    +'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" '
    +'showcontrols="true" uimode="full" width="300" height="300" '
    +'src="'+what+'" autostart="true" loop="true">'
    <INPUT TYPE="button" value="Refresh this page" onClick="parent.location='index.asp'">
    Response.AddHeader "Pragma", "No-Cache"	'try not to cache page
    Response.CacheControl = "Private"		'try not to cache page
    	server.scripttimeout = 300		'script will time out after 5 minutes
    dim filecounter, searchtext, directory	'dimention variables
    dim fcount, fsize
    filecounter = 0				'initialize filecounter to zero
    searchtext = Trim(request("SearchText"))	'get the querystring SearchText
    directory = Trim(request("Directory"))		'get the querystring Directory
    if directory = "" then directory = "C:\inetpub\wwwroot\clips\video\"	'if no directory the set to c:\
    						'Write the Search Form to the page
    response.write "<form name='f2' action='index.asp' method=get>" & _
    	" <input type=text name=SearchText size=20 value=" & Chr(34) & searchtext & _
    	Chr(34) & "> <input type=hidden name=Directory size=20 value=" & _
    	Chr(34) & directory & Chr(34) & "> <input type=submit value='Search Newsclips' onClick='parent.location='index.asp'></form><br></div>"
    if searchtext <> "" Then	'if there is a file to search for then search
     set rs = createobject("adodb.recordset")
     rs.fields.append "FilePath",200,255
    	 rs.fields.append "FileName",200,255
     rs.fields.append "FileSize",200,255
    	 rs.fields.append "FileDate",7,255
    	Recurse directory	'call the subroutine to traverse the directories
    	Sub Recurse(Path)
    			'create the file system object
    		Dim fso, Root, Files, Folders, File, i, FoldersArray(1000)
    		Set fso = Server.CreateObject("Scripting.FileSystemObject")
    		Set Root = fso.getfolder(Path)
    		Set Files = Root.Files
    		Set Folders = Root.SubFolders
    		fcount = 0			'zero out the file count variable
    			'traverse through the subdirectories in the current directory
                    Response.Write ("<form action=""submit.asp"" method=""post"" name=""f1"">")
                    Response.Write ("<center><select name=""files"" onchange=""PlayIt(this.value);this.blur()"" >")
                    Response.Write ("<option value=""null.mpg"">" & "-- Please Select Searched Newsclip --" & "</option>")
    		For Each Folder In Folders
    			FoldersArray(i) = Folder.Path
    			i = i + 1
    			'traverse through the files in the current folder or subfolder
    		For Each File In Files
    				'check if the search string is found
    			num = InStr(UCase(File.Name), UCase(searchtext))
    				'if it is then update the recordset and sort it
    			if num <> 0 then
    			filecounter = filecounter + 1
    		rs.fields("FilePath") = File.Path
    			rs.fields("FileName") = File.Name
     		rs.Sort = "FileName ASC"
    			end if
    			'recurse through the current directory until 
    			'all subfolders have been traversed
    		For i = 0 To UBound(FoldersArray)
    			If FoldersArray(i) <> "" Then 
    				Recurse FoldersArray(i)				
    				Exit For
    			End If
    	End Sub
    		'if files were found then write them to the document
    	If filecounter <> 0 then
    			filecounter = 0
    		do while not rs.eof
    			filecounter = filecounter + 1
                    Response.Write ("<option value=""" & "video/" & rs.fields("FileName") & """>" & rs.fields("FileName") & "</option>" & vbCrLf)
    		Response.Write ("</select>")	
    		Response.Write("no files found") 	'no files were found
    	end if
    end if
    <input type="submit" value="Send this clip to Carbon Farm"> 
    <div id="video" align="center">
    <object width="300" height="300" 
    standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">
    <param name="url" value="null.wmv">
    <param name="uiMode" value="full">
    <param name="autoStart" value="true">
    <param name="loop" value="true">
    <embed type="application/x-mplayer2" 
    showcontrols="true" uimode="full" width="300" height="300" 
    src="" autostart="1" loop="true">
  8. #5
  9. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2013
    Roanoke, VA
    Rep Power
    Thanks for your response gk53. I found a link that helped me do what I wanted to do; however, I am moving in a different direction. Now, I am writing the files to a database and pulling from the database. I tried to post the link to the page that helped me but it said a moderator needed to verify my post and it's been a week and....well....thanks anyway.

Similar Threads

  1. Delete files in folder that are 1 day old?
    By jollyfriartuck in forum ASP Development
    Replies: 3
    Last Post: August 17th, 2006, 08:17 AM
  2. Replies: 1
    Last Post: October 20th, 2005, 07:27 AM
  3. delete files from folder
    By gogaak in forum ASP Development
    Replies: 3
    Last Post: May 27th, 2005, 09:13 AM
  4. search network folder for pdf files inline
    By frodiggs in forum ASP Development
    Replies: 3
    Last Post: December 23rd, 2004, 04:03 PM
  5. copy files from shared folder to the local C:\ folder
    By kiran_karnati in forum Visual Basic Programming
    Replies: 1
    Last Post: September 27th, 2004, 05:34 PM

IMN logo majestic logo threadwatch logo seochat tools logo