Click here to Skip to main content
Click here to Skip to main content

Find files with JavaScript

, 25 Mar 2002
Rate this:
Please Sign up or sign in to vote.
Find files or directory in client or server site with JavaScript


Maybe you want to have list of  server or client files in your web page to uploading or downloading or changing . JScript allow you to do this. You can capture all files type , size , properties in all directories and use them easily. In this sample I use this technique for searching files in local hard drive.

Necessary Attention: your browser should have access to run ActiveX objects. If receive a error message telling "Automatic Server Can't Create Object" you most go to Internet Option and in security tab select custom level in Local part and change options to get effect.

ActiveX Objects

For working with Files and directory you should make a server object as Scripting.FileSystemObject then with GetDirectory() method can get a directory object. If you want know the directory is use FolderExists().

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


Enumerators are an array of Directory or File objects such that you can use methods to get special file or sub directory that are in defined path. Enumerator have some methods I have called like atEnd() and moveNext() in my sample.

function FindFile(FOo)
    //Get array of files including in FOo directory object
    var FSo = new Enumerator(FOo.Files);
    // Getting all files in FSo object
    for (i=0;!FSo.atEnd();FSo.moveNext())


Files Object Properties

For getting a object that is in Enumerator object you must use item() and it returns a file or directory object that are in current place of Enumerator. Then you can use Files properties that are listed.

  • Attributes
  • DateCreated
  • DateLastAccessed
  • DateLastModified
  • Drive
  • Name
  • ParentFolder
  • Path
  • ShortName
  • ShortPath
  • Size
  • Type
FSo.item().name // File name
FSo.item().type // Description defining the file extension
FSo.item().size // File size in byte


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

AFShin Dehghani
Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
No Biography provided

Comments and Discussions

QuestionCan the results be pushed to an Excel spreadhseet? Pinmemberpopsui14-Oct-08 11:42 
AnswerRe: Can the results be pushed to an Excel spreadhseet? [modified] PinmemberUno198231-Dec-08 10:22 
AnswerRe: Can the results be pushed to an Excel spreadhseet? PinmemberUno198216-Sep-09 11:11 
GeneralI can see nothing happenned=( Pinmembernguk30-May-08 17:35 
Generalno file found or search in progress [modified] Pinmembercrichardson1828-Apr-08 8:23 
GeneralRe: no file found or search in progress PinmemberUno198213-Aug-09 10:42 
GeneralRe: no file found or search in progress Pinmembercrichardson1824-Aug-09 6:57 
GeneralRe: no file found or search in progress PinmemberUno198224-Aug-09 9:41 
Thanks very much. I'll actually be modifying this code once again with 2 new functions. It has been requested by a company I work for to add the ability to build an excel document out of the page results and email this excel document from the webserver. This will change the page into an .asp page using vbscript to call the server side functions for email to build the excel document. I will post the updated page when this is finished. I may actually work on a client side version that continues to use nothing but javascript and activex but more research will be needed on my part to see if this is possible.
Thanks again for validating my time with this application.
GeneralUpdate to sort by date (Delete function added) PinmemberUno19823-Apr-08 7:17 
GeneralRe: Update to sort by date (Delete function added) [I know this code is buggy] PinmemberUno198231-Dec-08 10:56 
GeneralVery Cool Pinmemberjftejadal28-Mar-08 12:36 
GeneralUPDATE!! Sorting by Date() function PinmemberUno198227-Mar-08 12:23 
Questiondo not work in my computer Pinmemberemari216-Nov-07 5:19 
Questionhow to get the textfile from the system without giving the foldername in javascript in dynamically Pinmemberharikagupta2-Oct-07 21:39 
QuestionEnumeration error Pinmemberlife_program10-Aug-07 9:30 
GeneralGood Very Good Pinmembernaimisar25-Jul-07 20:00 
GeneralFinding files without using ActiveX PinmemberKeertikiran15-May-07 22:09 
GeneralRe: Finding files without using ActiveX PinmemberUno198213-Aug-09 10:47 
Generala comment from nee_bhatia PinstaffSean Ewington8-May-07 4:29 
GeneralDisplay Files after Sorting. [modified] PinmemberKeertikiran4-Apr-07 0:09 
GeneralRe: Display Files after Sorting. PinmemberUno19823-Apr-08 5:14 
QuestionActiveXObject("Scripting.FileSystemObject") in Mozilla Pinmembermegha.purkayastha29-Nov-06 3:08 
AnswerRe: ActiveXObject("Scripting.FileSystemObject") in Mozilla PinmemberUno198213-Aug-09 10:51 
GeneralFo is NULL or not an object [modified] PinmemberPeter from Hungary21-Jun-06 3:49 
GeneralRe: Fo is NULL or not an object PinmemberVijayashankarPalanichamy7-Oct-07 22:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web01 | 2.8.150414.1 | Last Updated 26 Mar 2002
Article Copyright 2002 by AFShin Dehghani
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid