|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
'object required' error using FileSystemObjecta 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 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 <goo***@westernwares.com> wrote in message Show quoteHide quote 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 > 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 -- Show quoteHide quote<goo***@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,
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: Show quoteHide quote > 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 > > -- > > <goo***@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 > > <%Option Explicit%> would have prevented that.
-- Show quoteHide quoteMike 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 > > > > -- > > > > <goo***@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 > > > Gazing into my crystal ball I observed "Mike Brind" <paxton***@hotmail.com> I love Option Explict so much I think I'll marry it ;-)writing in news:1154121251.171913.317950@m73g2000cwd.googlegroups.com: ><%Option Explicit%> would have prevented that. > > -- Adrienne Boswell at Home Arbpen Web Site Design Services http://www.cavalcade-of-coding.info Please respond to the group so others can share On 28/07/2006 17:23, hogwell wrote:
Show quoteHide quote > Stuart, As always, best to use Option Explicit on all scripts.> > 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 >> >> -- >> >> <goo***@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 >>> > Lee 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...... <goo***@westernwares.com> wrote in message Show quoteHide quote 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 >
ASP - Terminating objects in memory
Need Help. - Can't find my error Visual Interdev 6.0 ASP Excel worksheet ASP page that calls ActiveX object fails under x64 IIS 6 Call a javascript function from ASP page Real quick question Image server control - where am I going wrong? Display Large Images CodePage=65001, breakpoints not right |
|||||||||||||||||||||||