5,117,952 members and growing! (12,435 online)
Email Password   helpLost your password?
Web Development » Client side scripting » General     Intermediate

Find files with JavaScript

By AFShin Dehghani

Find files or directory in client or server site with JavaScript
JScriptNT4, Win2K, WinXP, Windows, Dev

Posted: 25 Mar 2002
Updated: 25 Mar 2002
Views: 127,356
Announcements



Search    
Advanced Search
Sitemap
27 votes for this Article.
Popularity: 5.94 Rating: 4.15 out of 5
3 votes, 12.5%
1
0 votes, 0.0%
2
1 vote, 4.2%
3
4 votes, 16.7%
4
16 votes, 66.7%
5

Introduction

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");

Enumerator

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

License

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



Occupation: Web Developer
Location: Iran, Islamic Republic Of Iran, Islamic Republic Of

Other popular Client side scripting articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 33 (Total in Forum: 33) (Refresh)FirstPrevNext
Subject  Author Date 
Generalno file found or search in progressmembercrichardson188:23 28 Apr '08  
GeneralUpdate to sort by date (Delete function added)memberUno19827:17 3 Apr '08  
GeneralVery Coolmemberjftejadal12:36 28 Mar '08  
GeneralUPDATE!! Sorting by Date() functionmemberUno198212:23 27 Mar '08  
Questiondo not work in my computermemberemari25:19 16 Nov '07  
Generalhow to get the textfile from the system without giving the foldername in javascript in dynamicallymemberharikagupta21:39 2 Oct '07  
QuestionEnumeration errormemberlife_program9:30 10 Aug '07  
GeneralGood Very Goodmembernaimisar20:00 25 Jul '07  
GeneralFinding files without using ActiveXmemberKeertikiran22:09 15 May '07  
Generala comment from nee_bhatiastaffSean Ewington4:29 8 May '07  
GeneralDisplay Files after Sorting. [modified]memberKeertikiran0:09 4 Apr '07  
GeneralRe: Display Files after Sorting.memberUno19825:14 3 Apr '08  
QuestionActiveXObject("Scripting.FileSystemObject") in Mozillamembermegha.purkayastha3:08 29 Nov '06  
GeneralFo is NULL or not an object [modified]memberPeter from Hungary3:49 21 Jun '06  
GeneralRe: Fo is NULL or not an objectmemberVijayashankarPalanichamy22:24 7 Oct '07  
GeneralRe: Fo is NULL or not an objectmemberUno198211:13 3 Apr '08  
GeneralSerach on a servermemberCarlos S.7:27 28 Oct '05  
AnswerRe: Serach on a servermemberAFShin Dehghani20:50 28 Oct '05  
GeneralWhat happened???memberWeishun16:06 20 Nov '04  
GeneralRe: What happened???memberharikagupta21:13 4 Oct '07  
GeneralDocumentationmemberjajansse0:05 13 Aug '04  
GeneralRe: Documentationmemberoregano18:54 20 Jul '05  
GeneralRunning this code in a clientmemberSeveredlimb9:37 24 Jun '03  
GeneralRe: Running this code in a clientsussAnonymous9:52 20 Jul '05  
GeneralInclude Sub Directorymemberafs6:50 26 Mar '02  

General General    News News    Question Question    Answer Answer    Joke Joke