Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return multiple files with GetFile method

Status
Not open for further replies.

robertl

Programmer
Jan 8, 2001
23
GB
Someone on this board directed me to another site that contained information regarding the FileSystemObject Objects.

After experimenting with the Objects, I'm able to successfully list all files from a directory that I specify
using the Files collection or I can display the name of
one file using the File object.

What I'm wanting to do is display all the files that have
an extension of .xls for instance. I don't think the Files collection will let me restrict what files to bring back, yet the file object seem to only want to return one file.

Anyone have any insight into this?

Thanks.

Code:
   var fso, fldr, fl;
	fso = new ActiveXObject "Scripting.FileSystemObject");
	fldr = fso.GetFolder("c:\\folder\\subfolder");
         Response.Write(fldr.Name);
	fl = fso.GetFile("c:\\folder\\subfolder\\BCEU.xls"); 'there is actually multiple .xls files to return, but can only seem to specify one file.
	Response.Write(fl.Name);
 
maybe iterate through the files collection with a for loop and only retrieve the file (and store it in another array?) if it has the .xls extension jared@aauser.com
 
I cleaned up the code to have the following all the while
trying to insert the file names into an array so I could check the substring and find out if it would equal ".xls".

This is what I have:
Code:
   var fso, fldr, fc, c;
  		files = new Array(10);
	fso = new ActiveXObject("Scripting.FileSystemObject");
	fldr = fso.GetFolder("c:\\gearbulk\\schedules");
	fc = new Enumerator(fldr.files);
	for (fc; !fc.atEnd(); fc.moveNext())
	{
	  c = (fc.item() + &quot;<br>&quot;);

I'm not doing anything with files right now as if I replace the c with files I end up with with not only the list of files, but they repeat as well.

Apparently one is forced to use the new Enumerator to pull multiple files as for taking each item (including the line break) and storing them into an array, I'm at a lost unless I'm missing some syntax somewhere regarding the filesystemobject.

 
can you do a for .. in loop and do

for (fl in fldr.files) {
response.write fl.name
} ray
rheindl@bju.edu

 
I'm looking at your script, and have no real javascript experience, and some visual basic experience. I want to list the contents of a directory on my ISP. Can someone direct me to some other articles or help how I can make that happen, maybe using the script above? .:TUCK:.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top