performance of FileSystem-object 
Author Message
 performance of FileSystem-object

I'm using FileSystem.object to display all files and subfolders
of a certain folder on the client maschine.
Code is executed inside an .hta.

This works fine with few local files, but gets
extremly slow when accessing folders with more than
500 files or folders on LAN-network drives.

This is the code I use: (it's copied from msdn):

function ShowFolderFileList(folderspec)
{
   var fso, f, f1, fc, s;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   f = fso.GetFolder(folderspec);
   fc = new Enumerator(f.files);
   s = "";
   for (; !fc.atEnd(); fc.moveNext())
   {
      s += fc.item();
      s += "<br>";
   }
   return(s);

Quote:
}

If I access fc.item() with let's say fSize=fc.item().Size
performance gets even worth.
Does anybody know a faster way to collect
folder information like subfolders and files ?
I do not need a handle to the files, I only want to
retrieve names and sizes of subfolders and files.

thanks in advance,
Michael Wender

PS: I know the script is JScript, but usually VBScript-groups are
more into FileSystemObject - so please don't blame me for that..



Mon, 22 Sep 2003 16:45:59 GMT  
 performance of FileSystem-object
You're always going to take a performance hit accessing files over a
network. Not too sure what you can do about that.

But your biggest hit is coming from string manipulation. Every time you
append to a string, JScript has to make a completely new string and destroy
the old one. Your loop appends to the string twice! Changing it to append
only once speeds up the loop by a factor of two (surprise!).

  for (; !fc.atEnd(); fc.moveNext())
  {
     s += fc.item()+"<br>";
  }

But for real time savings, don't manipulate strings inside a loop! Array
manipulation is relatively cheap.

  s = new Array();
  for (; !fc.atEnd(); fc.moveNext())
  {
    s[s.length] = fc.item();
  }
  s = s.join("<br>");

=-=-=
Steve
-=-=-


Quote:
> I'm using FileSystem.object to display all files and subfolders
> of a certain folder on the client maschine.
> Code is executed inside an .hta.

> This works fine with few local files, but gets
> extremly slow when accessing folders with more than
> 500 files or folders on LAN-network drives.

> This is the code I use: (it's copied from msdn):

> function ShowFolderFileList(folderspec)
> {
>    var fso, f, f1, fc, s;
>    fso = new ActiveXObject("Scripting.FileSystemObject");
>    f = fso.GetFolder(folderspec);
>    fc = new Enumerator(f.files);
>    s = "";
>    for (; !fc.atEnd(); fc.moveNext())
>    {
>       s += fc.item();
>       s += "<br>";
>    }
>    return(s);
> }

> If I access fc.item() with let's say fSize=fc.item().Size
> performance gets even worth.
> Does anybody know a faster way to collect
> folder information like subfolders and files ?
> I do not need a handle to the files, I only want to
> retrieve names and sizes of subfolders and files.

> thanks in advance,
> Michael Wender

> PS: I know the script is JScript, but usually VBScript-groups are
> more into FileSystemObject - so please don't blame me for that..



Mon, 22 Sep 2003 20:26:15 GMT  
 performance of FileSystem-object
Thanks for your reply Steve.
Actually what I'm doing is exactly what you proposed.
I'm gathering information by storing it into an array;
But the lack of performance is due to the filesystemobject,
occuring when accessing the File-object.

So if I change my code to:
###
 for (; !fc.atEnd(); fc.moveNext())
 s[s.length] = fc.item(); <--- just getting File-Object
 }
###
That's very fast.

But:
###
 for (; !fc.atEnd(); fc.moveNext())
 s[s.length] = fc.item().Name; <--- accessing the File-Object

Quote:
}

###
This results in poor perfomance.

I guess JScript is really accessing each file
in the second case.
What I need is just names and sizes of files;
I don't need any further information.

Any idea how to do that - maybe without filesystemobject ?
Maybe some ActiveX-Object that could do that ?

best regards,
Michael Wender


Quote:
> You're always going to take a performance hit accessing files over a
> network. Not too sure what you can do about that.

> But your biggest hit is coming from string manipulation. Every time you
> append to a string, JScript has to make a completely new string and destroy
> the old one. Your loop appends to the string twice! Changing it to append
> only once speeds up the loop by a factor of two (surprise!).

>   for (; !fc.atEnd(); fc.moveNext())
>   {
>      s += fc.item()+"<br>";
>   }

> But for real time savings, don't manipulate strings inside a loop! Array
> manipulation is relatively cheap.

>   s = new Array();
>   for (; !fc.atEnd(); fc.moveNext())
>   {
>     s[s.length] = fc.item();
>   }
>   s = s.join("<br>");

> =-=-=
> Steve
> -=-=-



> > I'm using FileSystem.object to display all files and subfolders
> > of a certain folder on the client maschine.
> > Code is executed inside an .hta.

> > This works fine with few local files, but gets
> > extremly slow when accessing folders with more than
> > 500 files or folders on LAN-network drives.

> > This is the code I use: (it's copied from msdn):

> > function ShowFolderFileList(folderspec)
> > {
> >    var fso, f, f1, fc, s;
> >    fso = new ActiveXObject("Scripting.FileSystemObject");
> >    f = fso.GetFolder(folderspec);
> >    fc = new Enumerator(f.files);
> >    s = "";
> >    for (; !fc.atEnd(); fc.moveNext())
> >    {
> >       s += fc.item();
> >       s += "<br>";



Tue, 23 Sep 2003 17:25:22 GMT  
 performance of FileSystem-object
[ x-post & f'ups set to
microsoft.public.inetsdk.programming.scripting.jscript ]

A Q&D approach would be to capture the output of a DIR command and parse the
file created.

=-=-=
Steve
-=-=-


Quote:
> Thanks for your reply Steve.
> Actually what I'm doing is exactly what you proposed.
> I'm gathering information by storing it into an array;
> But the lack of performance is due to the filesystemobject,
> occuring when accessing the File-object.

> So if I change my code to:
> ###
>  for (; !fc.atEnd(); fc.moveNext())
>  s[s.length] = fc.item(); <--- just getting File-Object
>  }
> ###
> That's very fast.

> But:
> ###
>  for (; !fc.atEnd(); fc.moveNext())
>  s[s.length] = fc.item().Name; <--- accessing the File-Object
> }
> ###
> This results in poor perfomance.

> I guess JScript is really accessing each file
> in the second case.
> What I need is just names and sizes of files;
> I don't need any further information.

> Any idea how to do that - maybe without filesystemobject ?
> Maybe some ActiveX-Object that could do that ?

> best regards,
> Michael Wender



Tue, 23 Sep 2003 18:52:45 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to add records?

2. move INTERBASE ARRAY to DELPHI ARRAY ?

3. SEND KEY STROKES TO 5250 SESSION

4. Javascript performance with COM objects

5. Passing Arrays to COM Object Slows Performance

6. Client Side Objects Performance Issues

7. Extract Image out of OLE Object Field to Filesystem

8. Problem setting reference to FileSystemObject object

9. filesystem object

10. filesystem object and UNC?

11. FileSystem Object

12. filesystem object

 

 
Powered by phpBB® Forum Software