Skip to main content
December 9, 2008
Question

Check to see if a file exists

  • December 9, 2008
  • 2 replies
  • 831 views
Hello all,

I have a small problem that I can't seem to figure out. I have several .htm files that I will need to run through the .chm and I want to check to see if a file exists prior to attempting to load it. If the file does not exist, I want it to load a default "File not found" page that I will create in my .chm.

I am familiar with .net programming, but JavaScript is fairly new to me. If someone could point me in the right direction, I would appreciate it.

I will now go and keep googling...thanks in advanced for any help you can provide.
This topic has been closed for replies.

2 replies

December 16, 2008
Thanks John,

I was wondering though...how could I make this redirect the page to the file that I want? The page, if found, would be in the file system (%programfiles%\Alphav8\WhatsNew\WhatsNew.htm)

Can I have that file displayed in the .chm using this? If the file is not found, I would like to redirect the page to a topic that is in the .chm (.\failedtofind.htm).

Sorry for all the questions, I am not too familiar with VBScript, thanks.
Inspiring
December 16, 2008
Andrew,

It has been a while since I wrote this code, but I included the whole thing so you could see how it works. These days you may get a security warning based on your computer settings since scripts can be harmful. In this script, the text is directed to a message box. That is not what you want. I think I can combine this with a hidden link script and provide what you are looking for. I should be able to get to it sometime today. Just to be clear - you are producing a .chm output and the file is an external file, correct? What type of file is it - .doc, .txt, .htm, pdf? You can email me or post here.

John
Inspiring
December 16, 2008
By the way, I do not think it is possible to read a user's computer (search for files) from a CHM file without some kind of warning message from our Big Brother at Microsoft. I think things that are allowed by an application should be allowed by that application's help file. If you trust a company's executable to run on your computer, why is their companion help file seen as a security risk? It makes no sense to me but that's the way of things...

When you run a script to read the user's files, you will get a warning. If your users are knowledgable they can proceed. If not, they may panic.

John
Inspiring
December 9, 2008
Since you are using a .chm output, you can use VBScript. I'm sure there is also a way to do this in javascript, but I am not as conversant in javascript. I've attached code I used to test an annotation script. In looking at it, I should have put the script in the HEAD section. But this does work and lets the user know if the annotation file exists before they try to read it.

John