|
Home > Archive > IIS ASP > July 2006 > 'object required' error using FileSystemObject
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
'object required' error using FileSystemObject
|
|
| google@westernwares.com 2006-07-28, 7:26 am |
| 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
| |
| Janette 2006-07-28, 7:26 am |
| 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
<google@westernwares.com> wrote in message
news:1154060087.550490.294120@p79g2000cwp.googlegroups.com...
>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
>
| |
| Stuart Palmer 2006-07-28, 7:26 am |
| 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
--
<google@westernwares.com> wrote in message
news:1154060087.550490.294120@p79g2000cwp.googlegroups.com...
>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
>
| |
| James Jones 2006-07-28, 1:23 pm |
| 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......
<google@westernwares.com> wrote in message
news:1154060087.550490.294120@p79g2000cwp.googlegroups.com...
>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
>
| |
| hogwell 2006-07-28, 1:23 pm |
| 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!
Stuart Palmer wrote:[vbcol=seagreen]
> 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
>
> --
>
> <google@westernwares.com> wrote in message
> news:1154060087.550490.294120@p79g2000cwp.googlegroups.com...
| |
| Mike Brind 2006-07-28, 7:19 pm |
| <%Option Explicit%> would have prevented that.
--
Mike Brind
hogwell wrote:[vbcol=seagreen]
> 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!
>
> Stuart Palmer wrote:
| |
| Lee Taylor 2006-07-28, 7:19 pm |
| On 28/07/2006 17:23, hogwell wrote:
> 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!
>
> Stuart Palmer wrote:
>
As always, best to use Option Explicit on all scripts.
Lee
| |
| Adrienne Boswell 2006-07-30, 7:19 pm |
| Gazing into my crystal ball I observed "Mike Brind" <paxtonend@hotmail.com>
writing in news:1154121251.171913.317950@m73g2000cwd.googlegroups.com:
><%Option Explicit%> would have prevented that.
>
>
I love Option Explict so much I think I'll marry it ;-)
--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
|
|
|
|
|