Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VBScript - AGHHHHH

Options
  • 21-07-2004 11:32am
    #1
    Closed Accounts Posts: 25


    Got the following code in a file called fred.asp
    Also go the file fred.txt in the same folder.

    <html>
    <head>
    </head>
    <body>
    iii<BR>
    <script language="vbScript" runat="Server">
    document.write("Here 1<BR>")
    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
    Dim FSO,f,ts

    Set FSO = createObject("Scripting.FileSystemObject")
    If (FSO.FileExists("fred.txt")) Then
    document.write("File Exists")
    Else
    document.write("File DOES NOT Exist")
    End If

    Set FSO = nothing


    document.write("Here 2")
    </script>

    </body>
    </html>



    Does anyone know why I keep getting the File DOES NOT Exist message?


Comments

  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Should you be specifiying the path to Fred.txt as well as the filename?

    Something like If fso.FileExists("C:\foo\Fred.txt"). Maybe the FSO defaults to it's webpage's folder, I don't know but it just struck me that it was missing.


  • Closed Accounts Posts: 25 tonysoprano


    Cannot do C:\Blah\Blah\Blah\fred.txt as the file sits on my ISP which is unix. So I just give it the relative path "fred.txt" as opposed to /blah/blah/blah/fred.txt.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Try:

    fso.FileExists(Server.MapPath("fred.txt"))

    or

    fso.FileExists(Server.MapPath("./fred.txt"))

    Also as it's on a *nix box, then the filename is likely to be case sensitive too.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    <snip/>

    Actually just do what TC said ...


  • Closed Accounts Posts: 35 Ivan Dunaev


    the only way for such error is different case in filenames (like fred.txt and Fred.txt)

    also try FSO.FileExists(Server.Mappath(realative_path))


  • Advertisement
  • Closed Accounts Posts: 35 Ivan Dunaev


    sorry, typing too long )


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Righty, can I use FSO.FileExists(Server.MapPath("http://www.foo.com/foo.txt")? Forgive me, my asp is old and senile.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Originally posted by Evil Phil
    Righty, can I use FSO.FileExists(Server.MapPath("http://www.foo.com/foo.txt")? Forgive me, my asp is old and senile.
    Don't know if using the full URL is a good idea. We're talking about a *nix port of ASP, such as Chillisoft, and I don't know if it would be so integrated with Apache to be able to grab domain info.


  • Closed Accounts Posts: 35 Ivan Dunaev


    you cannot, i guess. Server.MapPath returns phisical path corresponding to the given relative (virtual) path. there is no phisical path for uri


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Originally posted by Ivan Dunaev
    you cannot, i guess. Server.MapPath returns phisical path corresponding to the given relative (virtual) path. there is no phisical path for uri
    Actually there is a physical path for any full URI on a given box, but you're right in that Server.MapPath does not appear to support full URI's, only relative ones.


  • Advertisement
  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Okay, I get it now.


  • Closed Accounts Posts: 25 tonysoprano


    Tried all of the above. Double checked filename[Caps/No Caps]. Still cannot find the file. Any other ideas. I am all out of them.


  • Moderators, Politics Moderators Posts: 39,765 Mod ✭✭✭✭Seth Brundle


    what happens - is there an error?
    is the file there?
    post the code as it is now.


  • Closed Accounts Posts: 25 tonysoprano


    Ok code is as above - top of post. When I use ./ OR htt::// notation I get the File DOES NOT Exist message.
    However when I use Server.MapPath(".") OR Server.MapPath("fred.txt")
    I get ann Error on the status bar of IE.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Could simply be a case that you have no read/write permissions - not an uncommon security precaution.


  • Moderators, Politics Moderators Posts: 39,765 Mod ✭✭✭✭Seth Brundle


    Originally posted by tonysoprano
    However when I use Server.MapPath(".") OR Server.MapPath("fred.txt")
    I get ann Error on the status bar of IE.
    error on the status bar? that would be client side and therefore not ASP.
    Go to your internet options >> advanced and turn off the Show Friendly errors message (if not already done)
    K.


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    I know very little about server side VBScript on *nix boxes but if for ASP you have to enclose your code in
    <%

    %>

    tags, it seems kinda like you code is trying to run client side and find fred.txt there.
    Or am I just an idiot and
    <script language="vbScript" runat="Server"> is equivalent ?


  • Closed Accounts Posts: 25 tonysoprano


    Can not get any of the suggestions supplied here to work. Ta anyway.

    So now looking at a different approach:

    When I call the following script file fred.asp from my browser[IE]


    <%@ language="VBScript" %>
    <%
    Option Explicit

    Response.Write(Server.MapPath("."))
    %>

    I GET EXACTLY THIS ON THE SCREEN:

    <%@ language="VBScript" %>
    <%
    Option Explicit

    Response.Write(Server.MapPath("."))
    %>


    Damn. Would anyone know why?


  • Registered Users Posts: 937 ✭✭✭Diddy Kong


    when you open it in ie are you opening it locally or from a server....are you using iis....ie are you opening you page as c:\blah\test.asp or http://localhost/blah/test.asp.....


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    Sorry if this is a silly question but are you sure your ISP supports ASP ?
    To do it on *nix they need special packages installed, I don't know if
    many *nix hosts would have that ?


  • Advertisement
  • Closed Accounts Posts: 1,746 ✭✭✭0utshined


    Hi,

    Change this line

    If (FSO.FileExists("fred.txt")) Then

    to

    If (FSO.FileExists("\fred.txt")) Then

    and you should be okay.

    0


Advertisement