Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can JS check if a file exists?

    Hello, Is there any way to check if a file exists (Like exe's, images, html docs, etc) with Javascript?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No. Javascript is not capable of that. You will have to use a Server Side language such as Perl, PHP, ASP or Java.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Yes, through XMLHTTP object. Something similar to this, you just need to check if the HTTP status is 404 or not. But server-side solution might be more appropriate for your situation.

  • #4
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please try the following script:


    var fso = new ActiveXObject("Scripting.FileSystemObject");
    filename="test.txt";
    if (fso.FileExists(filename)){
    // file exists
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •