Click here to Skip to main content
13,768,132 members
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 12 Dec 2007
Licenced CPOL

File Search using Javascript

, 12 Dec 2007
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 
AnswerRe: Works great but on local server only Pin
9-Feb-13 14:05
suss9-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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.181116.1 | Last Updated 13 Dec 2007
Article Copyright 2007 by Arun Jacob
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid