[英]Why doesn't my .JSX script recognize every image in a folder which I want to mass-resize?
I have this JSX script I created but I feel like it's not checking for every file type in the filelist
variable.我有我创建的这个 JSX 脚本,但我觉得它没有检查
filelist
变量中的每个文件类型。 Can someone take a look?有人可以看看吗? It's very frustrating when I have it running and then for some reason a non-descript error message pops up and then it stops
当我让它运行时非常令人沮丧,然后由于某种原因弹出一个非描述性错误消息然后它停止
Here is the script:这是脚本:
var inputFolder = Folder.selectDialog("Select a folder to process"),
fileList = inputFolder.getFiles(/\.(jpg|tif|psd|crw|cr2|nef|dcr|dc2|raw)$/i);
for(var i=0; i < fileList.length; i++) {
var doc = open(fileList[i]);
if(doc.width !== doc.height) {
if(doc.width > doc.height) {
doc.resizeCanvas(doc.width, doc.width)
} else {
doc.resizeCanvas(doc.height, doc.height)
}
}
if((doc.width && doc.height) > 1000) {
doc.resizeImage(1000, 1000);
} else {
doc.resizeImage(doc.width, doc.height);
}
doc.save();
doc.close();
}
It seems that Folder.getFiles()
doesn't accept RegExp
objects, it only accepts a string
or a function
, beside that, it will also include Folder
objects, you can change it to something like this to filter only files and only the file types you're interested in:似乎
Folder.getFiles()
不接受RegExp
对象,它只接受一个string
或一个function
,除此之外,它还将包括Folder
对象,您可以将其更改为类似这样以仅过滤文件和文件您感兴趣的类型:
function filter(file) {
return (file instanceof File && /\.(jpg|tif|psd|crw|cr2|nef|dcr|dc2|raw)$/i.test(file.name))
}
fileList = inputFolder.getFiles(filter);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.