[英]Check if file exists locally in Adobe Extendscript
我尝试使用普通的js循环检查本地文件(.jpg)。 我收到一个错误,例如文件5d3eb1905b243.jpg
不存在,但实际上确实存在。
另外,我不明白为什么else
语句不能正常工作,为什么5d3eb1905b243.jpg
不被none.jpg
代替。
也许这是问题所在?
这是代码:
if (obj[i].hasOwnProperty('sharedimage_id')) {
var imgFile = new File(
'/Users/student/Desktop/seminar_robobooks/archiv/img/' +
obj[i].sharedimage_id +
'.jpg',
);
if (imgFile.exists) {
noStroke(imgFile);
image(obj[i].sharedimage_id + '.jpg', 56.5, 70.793, 69, 42);
} else {
noStroke(imgFile);
image('none.jpg', 56.5, 70.793, 69, 42);
}
}
您没有为问题提供足够的上下文。
File
或XML
问题:您使用的是哪个Basil版本? v2(仍处于Beta版)?
下面是一些继续讨论的样板代码和一些指针。
var obj = [
{
sharedimage_id: '123456',
},
{
sharedimage_id: '789012',
},
];
for (var i = 0; i < obj.length; i++) {
// the File API test is part of Extendscript
// https://www.indesignjs.de/extendscriptAPI/indesign10/#File.html
var imgFile = new File('/absolute/path/to/' + obj[i].sharedimage_id + '.jpg');
if (imgFile.exists === true) {
// no stroke does not take an argument
//https://basiljs2.netlify.com/reference/color/nostroke
noStroke();
image(obj[i].sharedimage_id + '.jpg', 56.5, 70.793, 69, 42);
} else {
noStroke();
// the image needs also a path as the one above
// or should be in the data dir nest to the ID doc.
// ID doc needs to be saved for that
// https://basiljs2.netlify.com/reference/image/image
image('none.jpg', 56.5, 70.793, 69, 42);
}
}
PS,我是其中的一位作者,并且我链接到该参考的当前开发版本。 将来可能会断开链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.