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 7 13822
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
<go****@westernwares.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.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
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
--
<go****@westernwares.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.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
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......
<go****@westernwares.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.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,
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:
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
--
<go****@westernwares.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.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
<%Option Explicit%would have prevented that.
--
Mike Brind
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:
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
--
<go****@westernwares.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.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
>
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:
>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
--
<go****@westernwares.comwrote in message news:11**********************@p79g2000cwp.googleg roups.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
As always, best to use Option Explicit on all scripts.
Lee
Gazing into my crystal ball I observed "Mike Brind" <pa*******@hotmail.com>
writing in news:11**********************@m73g2000cwd.googlegr oups.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 This discussion thread is closed Replies have been disabled for this discussion. Similar topics
3 posts
views
Thread by Apostolis K. |
last post: by
|
3 posts
views
Thread by News Groups |
last post: by
|
1 post
views
Thread by contact |
last post: by
|
2 posts
views
Thread by RICHARD BROMBERG |
last post: by
|
7 posts
views
Thread by imatts |
last post: by
| | |
2 posts
views
Thread by Sneha Bele |
last post: by
| | | | | | | | | | | |