4 Replies Latest reply on Dec 16, 2008 1:08 PM by johnmccallum

    Check to see if a file exists

    anubisascends
      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.
        • 1. Re: Check to see if a file exists
          Level 2
          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
          • 2. Re: Check to see if a file exists
            anubisascends Level 1
            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.
            • 3. Re: Check to see if a file exists
              Level 2
              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
              • 4. Re: Check to see if a file exists
                Level 2
                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