1 Reply Latest reply on May 24, 2014 4:52 AM by tehinternets

    How to check if file exists?


      Hi Guys.


      I'm running javascript in Acrobat on a .pdf created in LiveCycle Designer.


      I need to silently check if an external file outside of the open document ( C:\something\something\something.pdf ) exist or not.


      I understand that I may only be able to do this as a trusted function within a folder-level javascript.  I am familiar with those.   The problem is, I'm not sure what function I should be using and am having a hard time researching it.


      Attempt to use:  doc.exists?

      Try to open the document with a function and catch the error if the file doesn't exist?


      I am also not sure if I can simply pass my path as a string, say "/C/Something/something/something.pdf" or if first I need to treat the file as an object like:

      var myFile = new File("/C/Something/something/something.pdf")           (that was failing in Acrobat....didn't try running it as a trusted function)


      Please advise.


        • 1. Re: How to check if file exists?
          tehinternets Level 1

          I ended up figure this out myself.


          From the XFA/javascript within my document I call a custom function I wrote and pass it a string (or variable containing string) of my file path I wish to check for:


          if(typeof(MJS_FileExists) == "function") {
              try {
                  if(MJS_FileExists("/C/something/somethingelse/filetocheckfor.pdf") == true) {
                      xfa.host.messageBox("file is there");
                  } else {
                      xfa.host.messageBox("file is NOT there");
              catch(e) {
                  app.alert("Processing error: "+e)


          The function I am calling is a folder level javascript.   You may need to do some Googleing on how/where to install them.   In my actual folder level javascript's .js file where the function is housed I am using:

          var MJS_FileExists = app.trustedFunction(function(filename) {
              var existingDoc = false;
              try {
                   var checkDoc = app.openDoc(filename);
               existingDoc = true;
              } catch(e) {
               existingDoc = false;
              return existingDoc;


          This took me a lot of trial and error.  It sucks there's not a lot of into on the internet about how to do this through Acrobat / Live Cycle.   Hopefully this helps someone else.