Click here to Skip to main content
6,290,721 members and growing! (15,694 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
JavascriptWin2K, WinXP, Dev
Posted:25 Mar 2002
Views:160,954
Bookmarked:37 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
32 votes for this article.
Popularity: 6.19 Rating: 4.11 out of 5
4 votes, 13.8%
1

2
1 vote, 3.4%
3
4 votes, 13.8%
4
20 votes, 69.0%
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


Member

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

Other popular Client side scripting articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 40 (Total in Forum: 40) (Refresh)FirstPrevNext
QuestionHI, can i link results to the files!? PinmemberALEX CHIHAI11:16 16 Jun '09  
GeneralAdvanced Search including files from subdirectories, progressbar and delete function PinmemberUno19827:38 7 Jan '09  
GeneralRe: Advanced Search including files from subdirectories, progressbar and delete function PinmemberUno19825:33 22 Apr '09  
GeneralCan the results be pushed to an Excel spreadhseet? Pinmemberpopsui11:42 14 Oct '08  
GeneralRe: Can the results be pushed to an Excel spreadhseet? [modified] PinmemberUno198210:22 31 Dec '08  
GeneralI can see nothing happenned=( Pinmembernguk17:35 30 May '08  
Generalno file found or search in progress [modified] Pinmembercrichardson188:23 28 Apr '08  
GeneralUpdate to sort by date (Delete function added) PinmemberUno19827:17 3 Apr '08  
GeneralRe: Update to sort by date (Delete function added) [I know this code is buggy] PinmemberUno198210:56 31 Dec '08  
GeneralVery Cool Pinmemberjftejadal12:36 28 Mar '08  
GeneralUPDATE!! Sorting by Date() function PinmemberUno198212:23 27 Mar '08  
Questiondo not work in my computer Pinmemberemari25:19 16 Nov '07  
Generalhow to get the textfile from the system without giving the foldername in javascript in dynamically Pinmemberharikagupta21:39 2 Oct '07  
QuestionEnumeration error Pinmemberlife_program9:30 10 Aug '07  
GeneralGood Very Good Pinmembernaimisar20:00 25 Jul '07  
GeneralFinding files without using ActiveX PinmemberKeertikiran22:09 15 May '07  
Generala comment from nee_bhatia PinstaffSean Ewington4:29 8 May '07  
GeneralDisplay Files after Sorting. [modified] PinmemberKeertikiran0:09 4 Apr '07  
GeneralRe: Display Files after Sorting. PinmemberUno19825:14 3 Apr '08  
QuestionActiveXObject("Scripting.FileSystemObject") in Mozilla Pinmembermegha.purkayastha3:08 29 Nov '06  
GeneralFo is NULL or not an object [modified] PinmemberPeter from Hungary3:49 21 Jun '06  
GeneralRe: Fo is NULL or not an object PinmemberVijayashankarPalanichamy22:24 7 Oct '07  
GeneralRe: Fo is NULL or not an object PinmemberUno198211:13 3 Apr '08  
GeneralSerach on a server PinmemberCarlos S.7:27 28 Oct '05  
AnswerRe: Serach on a server PinmemberAFShin Dehghani20:50 28 Oct '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 25 Mar 2002
Editor: Nishant Sivakumar
Copyright 2002 by AFShin Dehghani
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project