Click here to Skip to main content
11,931,975 members (52,511 online)
Click here to Skip to main content
Add your own
alternative version


14 bookmarked

File Search using Javascript

, 12 Dec 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
Search files in client machine using javascript.


This is used for searching files in the client machine using javascript.

Using the code

Before running this,go to Internet explorer>Tools>Internet options>Security>Customlevel> and then enable 'Initialize and scriptActiveX controls not marked as safe.

I am using an ActiveXObject Scripting.FileSystemObject for searching drives,folders,subfolders and files in the client machine..

var fSObj =new ActiveXObject("Scripting.FileSystemObject");

As the first step on body onload we are filling the dropdownlist ddlDrive with the drives in the system using this ActiveXObject.And after selecting drive and entering file name to search,we are calling a recursive function RecursiveSearch(path) to iterate through all folders and subfolders in the selected drive.
function RecursiveSearch(path)
    	var txtSearch=document.getElementById('txtSearch');
	var txtToSearch=new String(txtSearch.value);
	var enObj = new Enumerator(fSObj.GetFolder(path).Files);
		var fileName=new String(enObj.item(i).name);
		if(txtToSearch==fileName ||>-1)
			..........			}
	var enObj = new Enumerator(fSObj.GetFolder(path).SubFolders);
		var path=new String(enObj.item(i).path);

We are also using enumerator while retrieving folders or files.

var enObj = new Enumerator(fSObj.GetFolder(path).Files);

Points of Interest

Did you learn anything interesting/fun/annoying while writing the code? Did you do anything particularly clever or wild or zany?


Keep a running update of any changes or improvements you've made here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Arun Jacob
Software Developer Tata Consultancy Services
India India
I have been working in different .NET Technologies like ASP.NET,WPF,Silverlight for the last few years.I am enjoying my life as a Programmer and spending time with my Family,Friends & Camera.

My Technical Blog

My Photo Blog

You may also be interested in...

Comments and Discussions

QuestionWorks great but on local server only Pin
Member 98220279-Feb-13 13:34
memberMember 98220279-Feb-13 13:34 
I got this great piece of code to work in IE on my VPS. I have a MAC so I had to build and test this on my VPS. And it works great, but only when searching the E: drive. Not sure why it gives me "Finished Searching.No Records Found." when I put the same pdf files to search for on the C: drive on my VPS...?

The bigger problem though is, when I launch the page and run the search on a PC, off the VPS, I get "Finished Searching.No Records Found." whether I search on the C: or E: drives.

Any idea how to get this to work?

I have tech pdfs sitting in a folder on my VPS for our technicians to pull up based on what they are searching for. If I could get this to work for them via a browser instead of their local PCs (which can't hold all the PDFs) that would be awesome.

Thanks, Jo

AnswerRe: Works great but on local server only Pin
Rene Pilon9-Feb-13 14:05
memberRene Pilon9-Feb-13 14:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 13 Dec 2007
Article Copyright 2007 by Arun Jacob
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid