Click here to Skip to main content
11,927,006 members (54,029 online)
Click here to Skip to main content
Add your own
alternative version


53 bookmarked

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

You may also be interested in...

Comments and Discussions

Questiongvbfgkfbf Pin
rag12341-May-15 1:52
memberrag12341-May-15 1:52 
QuestionSubFolders Pin
Member 1104682731-Aug-14 1:16
memberMember 1104682731-Aug-14 1:16 
QuestionCan not find the file when i'm run pass IIS web server Pin
Member 109795676-Aug-14 16:43
memberMember 109795676-Aug-14 16:43 
Questionrecurse Pin
Tlhogi2420-May-14 23:24
memberTlhogi2420-May-14 23:24 
QuestionERROR .........resultset not positioned properly Pin
Member 965495830-Mar-14 20:41
memberMember 965495830-Mar-14 20:41 
Bugerror Pin
Member 965495817-Feb-14 0:52
memberMember 965495817-Feb-14 0:52 
GeneralRe: error Pin
Patrik Misencik19-Feb-14 3:24
memberPatrik Misencik19-Feb-14 3:24 
GeneralRe: error Pin
Member 965495819-Feb-14 19:15
memberMember 965495819-Feb-14 19:15 
Questionthanks mate Pin
ivan coene17-Jun-13 4:54
memberivan coene17-Jun-13 4:54 
GeneralMy vote of 5 Pin
Member 913753919-Jun-12 5:42
memberMember 913753919-Jun-12 5:42 
QuestionHow to add view option Pin
RishiRaut23-Jan-11 8:10
memberRishiRaut23-Jan-11 8:10 
QuestionHow to upload these files Pin
dsfdfdfdf343434322-Sep-10 4:31
memberdsfdfdfdf343434322-Sep-10 4:31 
QuestionCan this script be used to search .avi files? Pin
Dave Herrell25-Dec-09 8:09
memberDave Herrell25-Dec-09 8:09 
GeneralMy vote of 1 Pin
dvg.madhu7-Oct-09 21:19
memberdvg.madhu7-Oct-09 21:19 
GeneralUpdate!! - Export to excel spreadsheet added!! Pin
Uno198216-Sep-09 11:14
memberUno198216-Sep-09 11:14 
GeneralFIXED!!! New Windows Update Breaks ActiveX security fuctions Pin
Uno198215-Sep-09 11:04
memberUno198215-Sep-09 11:04 
GeneralFixed all bugs (toggle and path reset) known issue with script timeout Pin
Uno19822-Sep-09 11:47
memberUno19822-Sep-09 11:47 
GeneralRe: Fixed all bugs (toggle and path reset) known issue with script timeout Pin
lunar-fifth14-Sep-09 22:32
memberlunar-fifth14-Sep-09 22:32 
GeneralRe: Fixed all bugs (toggle and path reset) known issue with script timeout Pin
Uno198215-Sep-09 8:49
memberUno198215-Sep-09 8:49 
GeneralThere are 2 bugs left in my source code. Pin
Uno198214-Jul-09 6:43
memberUno198214-Jul-09 6:43 
QuestionHI, can i link results to the files!? Pin
ALEX CHIHAI16-Jun-09 11:16
memberALEX CHIHAI16-Jun-09 11:16 
AnswerRe: HI, can i link results to the files!? Pin
Uno198214-Jul-09 6:35
memberUno198214-Jul-09 6:35 
GeneralRe: HI, can i link results to the files!? Pin
RishiRaut23-Jan-11 8:06
memberRishiRaut23-Jan-11 8:06 
GeneralAdvanced Search including files from subdirectories, progressbar and delete function Pin
Uno19827-Jan-09 7:38
memberUno19827-Jan-09 7:38 
GeneralRe: Advanced Search including files from subdirectories, progressbar and delete function Pin
Uno198222-Apr-09 5:33
memberUno198222-Apr-09 5:33 

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 26 Mar 2002
Article Copyright 2002 by AFShin Dehghani
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid