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

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

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)
No Biography provided

Comments and Discussions

 
Questionrecurse PinmemberTlhogi2420-May-14 22:24 
QuestionERROR .........resultset not positioned properly PinmemberMember 965495830-Mar-14 19:41 
Bugerror PinmemberMember 965495816-Feb-14 23:52 
GeneralRe: error PinmemberPatrik Misencik19-Feb-14 2:24 
GeneralRe: error PinmemberMember 965495819-Feb-14 18:15 
Questionthanks mate Pinmemberivan coene17-Jun-13 3:54 
GeneralMy vote of 5 PinmemberMember 913753919-Jun-12 4:42 
QuestionHow to add view option PinmemberRishiRaut23-Jan-11 7:10 
QuestionHow to upload these files Pinmemberdsfdfdfdf343434322-Sep-10 3:31 
QuestionCan this script be used to search .avi files? PinmemberDave Herrell25-Dec-09 7:09 
GeneralMy vote of 1 Pinmemberdvg.madhu7-Oct-09 20:19 
GeneralUpdate!! - Export to excel spreadsheet added!! PinmemberUno198216-Sep-09 10:14 
Added the new function to export to excel after search completes.
Remember to follow the directions below or the code will not work.
 
___________________________________________________
Some may have downloaded the newly released code that contained all bug fixes to only realize that nothing seems to work at all. Expecially when using IE 7 and IE 8. This is due to a new security fix recently released by windows update. To fix this follow the instructions below once you have downloaded the advancedsearch.zip file and extracted it your your desktop.
 
1) Locate the advancedsearch.htm file and right click
2) go to properties then look at the bottom after security: "this file came from a different computer.." and click the unblock button.
3) make sure the file is loading into IE as from "My Computer" and not Internet Zone
 
The code should then function properly
GeneralFIXED!!! New Windows Update Breaks ActiveX security fuctions PinmemberUno198215-Sep-09 10:04 
GeneralFixed all bugs (toggle and path reset) known issue with script timeout PinmemberUno19822-Sep-09 10:47 
GeneralRe: Fixed all bugs (toggle and path reset) known issue with script timeout Pinmemberlunar-fifth14-Sep-09 21:32 
GeneralRe: Fixed all bugs (toggle and path reset) known issue with script timeout PinmemberUno198215-Sep-09 7:49 
GeneralThere are 2 bugs left in my source code. PinmemberUno198214-Jul-09 5:43 
QuestionHI, can i link results to the files!? PinmemberALEX CHIHAI16-Jun-09 10:16 
AnswerRe: HI, can i link results to the files!? PinmemberUno198214-Jul-09 5:35 
GeneralRe: HI, can i link results to the files!? PinmemberRishiRaut23-Jan-11 7:06 
GeneralAdvanced Search including files from subdirectories, progressbar and delete function PinmemberUno19827-Jan-09 6:38 
GeneralRe: Advanced Search including files from subdirectories, progressbar and delete function PinmemberUno198222-Apr-09 4:33 
QuestionCan the results be pushed to an Excel spreadhseet? Pinmemberpopsui14-Oct-08 10:42 
AnswerRe: Can the results be pushed to an Excel spreadhseet? [modified] PinmemberUno198231-Dec-08 9:22 
AnswerRe: Can the results be pushed to an Excel spreadhseet? PinmemberUno198216-Sep-09 10:11 

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.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 26 Mar 2002
Article Copyright 2002 by AFShin Dehghani
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid