I'm trying to determine if a specific .xml file exists on my desktop before running additional code. The following trusted script is in my Javascripts folder-level directory. The section commented as "First Part" below simply sets all fields of the form to be open/writable. The second part looks for a .xml file in which to import XFA data from.
在运行其他代码之前,我正在尝试确定桌面上是否存在特定的.xml文件。以下可信脚本位于我的Javascripts文件夹级目录中。下面评论为“第一部分”的部分只是将表单的所有字段设置为开放/可写。第二部分查找要从中导入XFA数据的.xml文件。
My problem is that I'm trying to determine whether this .xml file exists in the first place. Right now if it doesn't exist, it displays a dialog window to browse for the file. Instead I'd like it to show an alert if the xml file does not exist, and never show the dialog at all. What am I doing wrong?
我的问题是我正在尝试确定这个.xml文件是否存在于首位。现在,如果它不存在,它会显示一个对话框窗口来浏览该文件。相反,如果xml文件不存在,我希望它显示警告,并且根本不显示对话框。我究竟做错了什么?
Any help is huge, thanks
任何帮助都是巨大的,谢谢
CODE:
var myTrustFunctTwo = app.trustedFunction(function(doc)
{
//First Part
for (var nPageCount = 0; nPageCount < doc.numPages; nPageCount++) {
var oFields = doc.xfa.layout.pageContent(nPageCount, "field");
//app.alert(oFields,0);
var nNodesLength = oFields.length;
// Set the field property.
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {
oFields.item(nNodeCount).access = "open";
}
}
//Second Part
app.beginPriv();
doc.importXFAData({
cPath:"/c/Users/ME/Desktop/Filled_In.xml"
});
app.endPriv();
});
app.trustedFunction(myTrustFunctTwo);
UPDATE CODE INCLUDING TRY/CATCH BLOCKS
更新代码,包括尝试/捕获块
var myTrustFunctTwo = app.trustedFunction(function(doc) {
for (var nPageCount = 0; nPageCount < doc.numPages; nPageCount++) {
var oFields = doc.xfa.layout.pageContent(nPageCount, "field");
//app.alert(oFields,0);
var nNodesLength = oFields.length;
// Set the field property.
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {
oFields.item(nNodeCount).access = "open";
}
}
try {
app.beginPriv();
doc.importXFAData({
cPath: "/c/Users/ME/Desktop/Filled_In.xml"
});
app.endPriv();
} catch (e) {
app.alert("No File Found", 1);
}
});
app.trustedFunction(myTrustFunctTwo);
1 个解决方案
#1
0
If the file you try to import does not exist, you will get an error message. Using try…catch
, you can catch that message and exit the function, thus prevent the subsequent code from running.
如果您尝试导入的文件不存在,您将收到一条错误消息。使用try ... catch,您可以捕获该消息并退出该函数,从而防止后续代码运行。
#1
0
If the file you try to import does not exist, you will get an error message. Using try…catch
, you can catch that message and exit the function, thus prevent the subsequent code from running.
如果您尝试导入的文件不存在,您将收到一条错误消息。使用try ... catch,您可以捕获该消息并退出该函数,从而防止后续代码运行。