Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

jscript fileexists not working

Posted on 2005-03-22
3
Medium Priority
?
321 Views
Last Modified: 2012-05-05
I've tried every conceivable file, both absolute and relative paths, in the same folder and in the root directory, and it simply doesn't work. It always says not found. Any suggestions?

var fs = new ActiveXObject("Scripting.FileSystemObject");

if(fs.FileExists("test.asp") == true)
{
      Response.Write("File exists.")
}
else
{
      Response.Write("File does not exist.")
}
0
Comment
Question by:arabiafish
  • 2
3 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13606595
Is this client or server code?  I am assuming the file is on the server, right?
0
 
LVL 14

Accepted Solution

by:
kiddanger earned 2000 total points
ID: 13607454
Try this instead...

var fs = new ActiveXObject("Scripting.FileSystemObject");

if(fs.FileExists(Server.MapPath("test.asp")) == true) {
  Response.Write("File exists.")
  } else {
  Response.Write("File does not exist.")
  }

Server.MapPath returns the physical path to the file.  Without it, you would have to put the physical path.  If you just put the file when using FSO, it first looks at the path of the ASP processor, which is usually %systemroot%\system32.

HTH...
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13636520
Thank you arabiafish.  (O:=
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question