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

Find files with JavaScript

By , 25 Mar 2002
 

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
Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberMember 913753919 Jun '12 - 4:42 
QuestionHow to add view optionmemberRishiRaut23 Jan '11 - 7:10 
QuestionHow to upload these filesmemberdsfdfdfdf343434322 Sep '10 - 3:31 
QuestionCan this script be used to search .avi files?memberDave Herrell25 Dec '09 - 7:09 
GeneralMy vote of 1memberdvg.madhu7 Oct '09 - 20:19 
GeneralUpdate!! - Export to excel spreadsheet added!!memberUno198216 Sep '09 - 10:14 
GeneralFIXED!!! New Windows Update Breaks ActiveX security fuctionsmemberUno198215 Sep '09 - 10:04 
GeneralFixed all bugs (toggle and path reset) known issue with script timeoutmemberUno19822 Sep '09 - 10:47 
GeneralRe: Fixed all bugs (toggle and path reset) known issue with script timeoutmemberlunar-fifth14 Sep '09 - 21:32 
GeneralRe: Fixed all bugs (toggle and path reset) known issue with script timeoutmemberUno198215 Sep '09 - 7:49 
GeneralThere are 2 bugs left in my source code.memberUno198214 Jul '09 - 5:43 
QuestionHI, can i link results to the files!?memberALEX CHIHAI16 Jun '09 - 10:16 
AnswerRe: HI, can i link results to the files!?memberUno198214 Jul '09 - 5:35 
GeneralRe: HI, can i link results to the files!?memberRishiRaut23 Jan '11 - 7:06 
GeneralAdvanced Search including files from subdirectories, progressbar and delete functionmemberUno19827 Jan '09 - 6:38 
GeneralRe: Advanced Search including files from subdirectories, progressbar and delete functionmemberUno198222 Apr '09 - 4:33 
QuestionCan the results be pushed to an Excel spreadhseet?memberpopsui14 Oct '08 - 10:42 
AnswerRe: Can the results be pushed to an Excel spreadhseet? [modified]memberUno198231 Dec '08 - 9:22 
AnswerRe: Can the results be pushed to an Excel spreadhseet?memberUno198216 Sep '09 - 10:11 
GeneralI can see nothing happenned=(membernguk30 May '08 - 16:35 
Generalno file found or search in progress [modified]membercrichardson1828 Apr '08 - 7:23 
GeneralRe: no file found or search in progressmemberUno198213 Aug '09 - 9:42 
GeneralRe: no file found or search in progressmembercrichardson1824 Aug '09 - 5:57 
GeneralRe: no file found or search in progressmemberUno198224 Aug '09 - 8:41 
GeneralUpdate to sort by date (Delete function added)memberUno19823 Apr '08 - 6:17 
GeneralRe: Update to sort by date (Delete function added) [I know this code is buggy]memberUno198231 Dec '08 - 9:56 
GeneralVery Coolmemberjftejadal28 Mar '08 - 11:36 
GeneralUPDATE!! Sorting by Date() functionmemberUno198227 Mar '08 - 11:23 
Questiondo not work in my computermemberemari216 Nov '07 - 4:19 
Questionhow to get the textfile from the system without giving the foldername in javascript in dynamicallymemberharikagupta2 Oct '07 - 20:39 
QuestionEnumeration errormemberlife_program10 Aug '07 - 8:30 
GeneralGood Very Goodmembernaimisar25 Jul '07 - 19:00 
GeneralFinding files without using ActiveXmemberKeertikiran15 May '07 - 21:09 
GeneralRe: Finding files without using ActiveXmemberUno198213 Aug '09 - 9:47 
Generala comment from nee_bhatiastaffSean Ewington8 May '07 - 3:29 
GeneralDisplay Files after Sorting. [modified]memberKeertikiran3 Apr '07 - 23:09 
GeneralRe: Display Files after Sorting.memberUno19823 Apr '08 - 4:14 
QuestionActiveXObject("Scripting.FileSystemObject") in Mozillamembermegha.purkayastha29 Nov '06 - 2:08 
AnswerRe: ActiveXObject("Scripting.FileSystemObject") in MozillamemberUno198213 Aug '09 - 9:51 
GeneralFo is NULL or not an object [modified]memberPeter from Hungary21 Jun '06 - 2:49 
GeneralRe: Fo is NULL or not an objectmemberVijayashankarPalanichamy7 Oct '07 - 21:24 
GeneralRe: Fo is NULL or not an objectmemberUno19823 Apr '08 - 10:13 
GeneralSerach on a servermemberCarlos S.28 Oct '05 - 6:27 
AnswerRe: Serach on a servermemberAFShin Dehghani28 Oct '05 - 19:50 
QuestionWhat happened???memberWeishun20 Nov '04 - 15:06 
AnswerRe: What happened???memberharikagupta4 Oct '07 - 20:13 
GeneralDocumentationmemberjajansse12 Aug '04 - 23:05 
GeneralRe: Documentationmemberoregano20 Jul '05 - 17:54 
GeneralRunning this code in a clientmemberSeveredlimb24 Jun '03 - 8:37 
GeneralRe: Running this code in a clientsussAnonymous20 Jul '05 - 8:52 

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 26 Mar 2002
Article Copyright 2002 by AFShin Dehghani
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid