acrobat xi -- use javascript to determine if a file exists
Another post from 2011, https://forums.adobe.com/thread/833146, seems to say there's no direct way to determine whether a file exists in the user's file system and that this is due to security concerns. A reply by try67, however, says "You can use openDoc on a certain path. If it returns null, the file doesn't exist. If it throws a security error, it exists but is not disclosed."
I'm hoping that between 2011 and now, Adobe (or someone) has come up with a simple way to test for file existence using javascript.
If not, I took try67's suggestion and came up with the following code which does seem to be able to test for file existence:
var myPathAndFile = "/serverName/faxes/christianBahnsen/test.pdf"
try {
existingDoc = app.openDoc({cPath: myPathAndFile, bHidden: true});
app.alert("this document name already exists!");
existingDoc.closeDoc();
} catch (e) {
var myFolder = "complete";
var myPathAndName = "./" + myFolder + "/newName2.pdf";
this.saveAs(myPathAndName);
};
It seems cumbersome to have to open the file to test for its existence and then immediately close it. I fail to see the problem/harm/risk with being able to test for a file's existence since I am able to open it. This script is also able to save the file with a new name if the file doesn't already exist.
I'm still learning adobe javascript. If someone has a more efficient way to accomplish the same end I'd love to see it.
Thanks
Christian Bahnsen
