All source code in ASP/ VbScript Ask a ASP/ VbScript Pro Discussion Forum Categories All jobs in ASP/ VbScript
Quick Search for:  in language:    
ASP,ever,want,search,files,using,your,browser
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 281,486. lines
 Jobs: 101. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login

NEW! LEARNING CENTER
Special educational offers, white papers, webcasts, podcasts

  NEW! Download Rational Performance Tester V8 (download now)
  NEW! Download Rational Functional Tester V8 (download now)
  NEW! Download Rational Service Tester for SOA Quality V8 (download now)
  NEW! Teleconference: Quality In Action - Using Rational Quality Manager with Functional, Performance and Web Service Testing Products (download now)
  NEW! Introducing IBM Rational AppScan Developer Edition – easing security testing by non-security professionals (download now)

 

 


Latest postings for ASP/ VbScript.
Click here to see a screenshot of this code!Mess Officer Management System (Sistem Pengurusan Mess Pegawai)
By Mohd Fauzi on 11/23

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

ASP File Finder

Print
Email
 
VB icon
Submitted on: 10/8/2000 2:00:31 AM
By: Blowno  
Level: Intermediate
User Rating: By 4 Users
Compatibility:ASP (Active Server Pages), HTML, VbScript (browser/client side)

Users have accessed this code 43205 times.
 
(About the author)
 
     Did you ever want to search for files using your web browser instead of the MS Find Files program? This ASP file searches your hard drive (or web server) for files containing a given string. You can specify a string to search for and the directory to search in (or leave the default c:\ directory).
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

    '**************************************
    ' for :ASP File Finder
    '**************************************
    NOTE: The code that traverses the folders was lifted from another app from the PSC site so I am not posting this For purposes of obtaining votes, but just for informational purposes.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: ASP File Finder
    ' Description:Did you ever want to searc
    '     h for files using your web browser inste
    '     ad of the MS Find Files program? This AS
    '     P file searches your hard drive (or web 
    '     server) for files containing a given str
    '     ing. You can specify a string to search 
    '     for and the directory to search in (or l
    '     eave the default c:\ directory).
    ' By: Blowno
    '
    ' Inputs:SearchText = The file containin
    '     g the text you are searching for.
    Directory = The Directory (and it's subdirectories) to search (default is c:\)
    '
    ' Returns:A list of files on your hard d
    '     rive (or web server) matching the string
    '     you searched for.
    '
    ' Assumes:I realize this app is much slo
    '     wer than the MS Find Files program, but 
    '     it is web enabled and will not return fi
    '     les that do not contain the search text 
    '     like the MS program does.
    '
    ' Side Effects:On slow machines - This s
    '     cript may time out if you search the ful
    '     l directory. Note: On my 1GHz machine it
    '     can take up to 2 minutes to search the e
    '     ntire 34GB hard drive (I set the script 
    '     timeout to 5 minutes).
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=6346&lngWId=4    'for details.    '**************************************
    
    <%@LANGUAGE="VBSCRIPT"%>
    <%
    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
    %>
    <HTML>
    <HEAD><TITLE>Find Files Using ASP</TITLE>
    <style>
    body {font:10pt Arial;background-color:papayawhip;color:antiquewhite;font-weight:bold;margin-top:0px;margin-left:0px;margin-right:0px}
    A:link {color:black;text-decoration:none}
    A:hover {color:red;text-decoration:underline}
    A:visited {color:black;text-decoration:none}
    td {color:black;border-bottom:1pt solid black;font:9pt Arial}
    th {color:black;border-bottom:1pt solid black;font:9pt Arial;font-weight:bold}
    </style>
    </HEAD>
    <BODY>
    <DIV style="background-color:tan">
    <CENTER>
    Find Files<BR>
    <%
    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:\"	'if no directory the Set to c:\
    						'Write the Search Form To the page
    response.write "<FORM action='FindFiles.asp' method=get>Search For:" & _
    	" <INPUT type=text name=SearchText size=20 value=" & Chr(34) & searchtext & _
    	Chr(34) & "> Change Directory: <INPUT type=text name=Directory size=20 value=" & _
    	Chr(34) & directory & Chr(34) & "> <INPUT style='background-color:blanchedalmond;" & _
    	"color:chocolate' type=submit value='Start Search'></FORM><BR></DIV>"
    if searchtext <> "" Then	'if there is a file To search For then search
    response.write "<TABLE border=0 width='100%'>"
    response.write "<TR><TH width='60%'>File Name</TH><TH width='10%'>File Size</TH><TH width='30%'>Date Modified</TH></TR>"
    		'create the recordset object To store
    		'the filepath, filename, filesize and last modified Date
    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
    rs.open
    	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
    		For Each Folder In Folders
    			FoldersArray(i) = Folder.Path
    			i = i + 1
    		Next
    			'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.addnew
    		rs.fields("FilePath") = File.Path
    			rs.fields("FileName") = File.Name
    			rs.fields("FileSize") = File.Size
    			rs.fields("FileDate") = File.DateLastModified
    			rs.update
    		rs.Sort = "FileName ASC"
    			End if
    		Next
    			'recurse through the current directory until 
    			'all subfolders have been traversed
    		For i = 0 To UBound(FoldersArray)
    			if FoldersArray(i) <> "" Then 
    				Recurse FoldersArray(i)				
    			Else
    				Exit For
    			End if
    		Next
    	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 "<TR><TD width='50%' valign=top><A href=""" & rs.fields("FilePath") & """>" & rs.fields("FileName") & "</TD><TD width='10%' align=right valign=top>"
    					'get the file size so we can
    					'assign the proper Bytes, KB or MB value
    				fsize = CLng(rs.fields("FileSize"))
    				'if less than 1 kilobyte Then it's Bytes
    			if fsize >= 0 And fsize <= 999 Then
    				fnumber = FormatNumber(fsize,0) & " Bytes"
    			End if
    				'if 1 KB but less Then 1 MB then assign KB
    			if fsize >= 1000 And fsize <= 999999 Then
    				fnumber = FormatNumber((fsize / 1000),2) & " KB"
    			End if
    				'if 1 MB or more Then assign MB
    			if fsize >= 1000000 Then
    				fnumber = FormatNumber((fsize / 1000000),2) & " MB"
    			End if
    				'write Each file and corresponding info To the document
    			response.write fnumber & "</TD><TD width='30%' align='center'>" & rs.fields("FileDate") & "</TD></TR>"
    			rs.movenext
    		Loop
    		response.write "</TABLE>"	'end the table
    	Else
    			'no files were found
    	End if
    End if
    %>
    </BODY>
    </HTML>

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
10/8/2000 2:16:42 AMblowno

Please give your feedback regarding this code - I am still working on allowing the user to key in wildcard strings such as "string*.jpg" - The code currently searches for the exact string within the file name. I'm not sure how to accomplish the wildcard search - Any feedback would be greatly appreciated.
(If this comment was disrespectful, please report it.)

 
1/17/2001 12:15:33 PMSam

I am trying to create a page that will allow individuals within my company intranet to easily copy files from their hard drive to our document folder on our server. However, when I try to use this code to view my local drive I get a Permission Denied error. It works well as long as I stay in the InetPub folder. Is there anyway around the Permission problem to view a file outside of the InetPub folder?
(If this comment was disrespectful, please report it.)

 
1/17/2001 11:31:43 PMBlowno

Sam - If the asp page is running on a server that is not on your local machine (such as pws) then it will not be able to search your local drive as that would be a security breach. Also, you cannot search in a domain other than the domain the file is located in.
(If this comment was disrespectful, please report it.)

 
1/19/2001 10:23:31 PMtest@testit.com

A file is missing. The missing file is: FindFiles.asp
(If this comment was disrespectful, please report it.)

 
1/20/2001 6:59:44 PMblowno

Hey Test - When you copy the code above, and paste it into a document, you need to name the document FindFiles.asp - Otherwise you need to change the submit parameter in the <Form> tag to whatever you named your document. It's submitting the form back to itsself. Thanks - Hope it works for you.
(If this comment was disrespectful, please report it.)

 
1/23/2001 3:51:49 PMHasse

It seems as if the last post got jammed, but what I wanted to know was: how can I use it for my website? What do I put for the Domain? server.mappath? And do I have to specify all my other directories?

thnx, Hasse
(If this comment was disrespectful, please report it.)

 
1/23/2001 4:06:50 PMHans Dahlgren

Hi,
Im trying to use your script (FindFiles), but it doesn't seem to work when I use it on my website... do I use
(If this comment was disrespectful, please report it.)

 
1/23/2001 11:10:42 PMblowno

To use this script on a web site just change the line that reads as follows:
if directory = "" then directory = "c:\" TO: if directory = "" then directory = server.mappath("/"), and then place the FindFiles.asp document in your root directory and it should search all of the directories on your web site.
(If this comment was disrespectful, please report it.)

 
1/24/2001 3:21:56 PMHasse

thnkz man, it works ok now! However, when I click the link to the document or picture, it doesn't go to the file, because the link is like this for example:

file:///C:/Inetpub/wwwroot/www.epartnersonline.com/images/phones/ericsson_r310s.jpg< BR>
And the browser doesn't under stand that it's actually a server it's looking for... how can I change this and only use the link "/images/phones/ericsson_r310s.jpg"???

/ Hasse
(If this comment was disrespectful, please report it.)

 
2/5/2001 8:14:14 AMDan Landry

I am kind of new to this code, I am having some trouble with it. I want to try and use this code to allow someone to enter a filename and search a server for it. How do I implement this code, I tried naming it FindFiles.asp, but it doesn't load anything. What am I doing wrong?
(If this comment was disrespectful, please report it.)

 
5/7/2001 11:33:47 AMXao Xiong

How do I list directory on a network? It works great listing directories/files from local drives, but crashes when I try to list "mapped" (M:\) or network drives (ie \\mycomputer\myshare). Does anybody have a solution for this?

Thank you,

Xao
(If this comment was disrespectful, please report it.)

 
5/23/2001 7:00:08 PMRon

Excellent! Just what I was looking for! It works great!
(If this comment was disrespectful, please report it.)

 
5/6/2002 2:20:43 AMSachp

The Code works great.Thanks
(If this comment was disrespectful, please report it.)

 
9/15/2002 11:52:26 PM

Response object error 'ASP 0156 : 80004005'

Header Error

/search.asp, line 41

The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.

(If this comment was disrespectful, please report it.)

 
10/23/2002 2:11:46 AM

excellent utility, practical and handy. i have my own solution to turning the physical dir to a virtual dir so the search result links work on the server : string manipulation. also, i added a few dirs to exclude from a search, as well as exclude certain file extentions. for example, don't want people downloading your .js files or other files, unless you want them to. the code i added is nothing flash, but it works and is functional. so if you need to look at it, email me.
(If this comment was disrespectful, please report it.)

 
1/29/2003 9:44:20 AM

I have the asp page on my webserver. How do you get it to search for a file on the client's machine? My search results have come back with nothing so far and I am assuming that it is searching on the server's file system and not on the clients.
(If this comment was disrespectful, please report it.)

 
5/25/2003 9:56:38 PM

this is good script!! and working properly...
but anybody can modify to increase the speed for serching file...please?!!
(If this comment was disrespectful, please report it.)

 
5/26/2003 11:01:55 PM

I get the following:

Microsoft VBScript runtime error '800a0046'
Permission denied

/FindFiles.asp, line 56


any suggestions?
(If this comment was disrespectful, please report it.)

 
3/4/2004 10:36:35 PM

Hi BlowNo,
(1) My drop list contain 2 drives (C: & M:).
codings:
if Drive_option.selected = "C:" then directory = "C:\" else if Drive_option.selected = "M:" then directory = "M:\"
**Drive_option is the name of my drop list

Is the above coding right?

(If this comment was disrespectful, please report it.)

 
6/23/2004 11:12:05 PM

The Code is great.
But I have the same problem as Hasss
However,when I click the link to the document
or picture, it doesn't go to the file,
because the link is like this for
example:

file:///C:/Inetpub/wwwroot/w
ww.epartnersonline.com/images/phones/eri
csso n_r310s.jpg

And the browser
doesn't under stand that it's actually
a server it's looking for... how can I
change this and only use the link
"/images/phones/ericsson_r310s.jpg"???

Can anyone help ??
(If this comment was disrespectful, please report it.)

 
1/30/2005 8:56:51 AMC. Sibon

For everybody with the path problem. Use an custom download script which can send the file to the client browser without it being in inetpub or even web shared. Create a file called download.asp and past the following code into it: (see next post)
(If this comment was disrespectful, please report it.)

 
1/30/2005 8:58:41 AMC. Sibon

<%@ Language=VBScript %> <% option explicit dim sFile, sRoot, sExt, objFSO, objStream, sFileSize, objFILESIZE 'change or make this line dynamic: sFile = "c:\pathtofilehere" set objFSO = server.CreateObject("Scripting.FileSystemObject") if not objFSO.FileExists(sFile) then Response.Write "Error: Failed to locate the file for binary read." Response.End end if set objFILESIZE = objFSO.GetFile(sFile) sExt = objFSO.GetExtensionName (sFile) sFileSize = objFILESIZE.size set objFSO = nothing set objFILESIZE = nothing
(If this comment was disrespectful, please report it.)

 
1/30/2005 8:59:20 AMC. Sibon

Response.ContentType = "application/octetstream"
Response.AddHeader "Content-Length", sFileSize
Response.AddHeader "Content-Disposition", "attachment; filename=" & Request.QueryString("file") & ";"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile sFile
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
Response.Flush
%>
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2008 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.