'object required' error using FileSystemObject

G

google

I am trying to use the following ASP code to examine the file names in
a folder:

Dim fso, f, fl, s, fs
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\Inetpub\wwwroot\MySite\subfolder")
Set fs = f.Files
For Each fl in fs
s = fl.Name 'Object Required error occurs here!
Response.Write(s)
Next
Set fso = Nothing

The asp page returns the 'Object Required' error on the line, "s =
fl.Name".
Why?

Can anyone shed any light on this?

Thanks
 
J

Janette

For what it is worth, I have run this as both a stand alone vbscript and as
an ASP page, and the only thing I changed was the path in the GetFolder
command, and it worked fine for both. Both for a folder that did and didn't
have contents. My only suggestions, are double check that you have the path
correct and check that you have appropriate permissions to the folder.

Also it might be worth running this script as a vbscript ie take the code,
put it in a file called xxxx.vbs, change response.write(s) to msgbox s, save
and run it by double clicking. This may help identify if it is a permissions
problem.

Hope this helps
Janette
 
S

Stuart Palmer

your code works for me, may be something to do with the path you have
stated. Try:

Dim fso, f, fl, s, fs
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(Server.MapPath("/subfolder"))
Set fs = f.Files
For Each fl in fs
s = fl.Name
Response.Write(s)
Next
Set fso = Nothing

might help fix the problem....but here it seems to work.

You may have other code in that file that is effecting this trouble line, in
which case, something like http://www.aspfaq.com/show.asp?id=2283 might be
somewhere to point you in (it might not have any direct relevance.

I would also recommend you choose better object names, I don't think the
ones you have chosen help debug.

Good luck.
Stu
 
J

James Jones

i dont think you can do a server.MapPath with folders beginning with a " / "

try

Set f = fso.GetFolder(Server.MapPath("subfolder/"))


that usually works for me.......



hope this helps......
 
H

hogwell

Stuart,

Thanks for this link, although I had already found this page myself
earlier.

I've now solved the problem, and this link turned out to be relevant
after all!

It was solved when I cut and pasted my code into this newsgroup for
further help.

Suddenly the 'fl' variable showed up as 'f1' - a typo!!!

My original code was written in Dreamweaver and the font they use for
code looks EXACTLY the same for the lower case letter L and the digit
One.

So, your comment about object names was also relevant - but note that
this code is taken verbatim from the Microsoft Help file for
FileSystemObject (except for the typo)!

Thanks everyone for the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top