Click here to Skip to main content
Licence 
First Posted 25 Mar 2002
Views 257,404
Downloads 5,217
Bookmarked 46 times

Find files with JavaScript

By AFShin Dehghani | 25 Mar 2002
Find files or directory in client or server site with JavaScript
5 votes, 16.7%
1

2
1 vote, 3.3%
3
4 votes, 13.3%
4
20 votes, 66.7%
5
4.78/5 - 33 votes
5 removed
μ 4.03, σa 2.63 [?]

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


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

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHow to add view option PinmemberRishiRaut8:10 23 Jan '11  
QuestionHow to upload these files Pinmemberdsfdfdfdf34343434:31 22 Sep '10  
QuestionCan this script be used to search .avi files? PinmemberDave Herrell8:09 25 Dec '09  
GeneralMy vote of 1 Pinmemberdvg.madhu21:19 7 Oct '09  
GeneralUpdate!! - Export to excel spreadsheet added!! PinmemberUno198211:14 16 Sep '09  
GeneralFIXED!!! New Windows Update Breaks ActiveX security fuctions PinmemberUno198211:04 15 Sep '09  
GeneralFixed all bugs (toggle and path reset) known issue with script timeout PinmemberUno198211:47 2 Sep '09  
GeneralRe: Fixed all bugs (toggle and path reset) known issue with script timeout Pinmemberlunar-fifth22:32 14 Sep '09  
GeneralRe: Fixed all bugs (toggle and path reset) known issue with script timeout PinmemberUno19828:49 15 Sep '09  
GeneralThere are 2 bugs left in my source code. PinmemberUno19826:43 14 Jul '09  
QuestionHI, can i link results to the files!? PinmemberALEX CHIHAI11:16 16 Jun '09  
AnswerRe: HI, can i link results to the files!? PinmemberUno19826:35 14 Jul '09  
GeneralRe: HI, can i link results to the files!? PinmemberRishiRaut8:06 23 Jan '11  
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  
QuestionCan the results be pushed to an Excel spreadhseet? Pinmemberpopsui11:42 14 Oct '08  
AnswerRe: Can the results be pushed to an Excel spreadhseet? [modified] PinmemberUno198210:22 31 Dec '08  
AnswerRe: Can the results be pushed to an Excel spreadhseet? PinmemberUno198211:11 16 Sep '09  
GeneralI can see nothing happenned=( Pinmembernguk17:35 30 May '08  
Generalno file found or search in progress [modified] Pinmembercrichardson188:23 28 Apr '08  
GeneralRe: no file found or search in progress PinmemberUno198210:42 13 Aug '09  
GeneralRe: no file found or search in progress Pinmembercrichardson186:57 24 Aug '09  
GeneralRe: no file found or search in progress PinmemberUno19829:41 24 Aug '09  
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  

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.

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