如何在VBScript中引用Photoshop文件夹对象



使用Adobe PhotoShop CS4脚本,JavaScript提供了FileFolder类,但我不知道如何从VBScript中使用这些类。

目前我使用DoJavaScript函数如下:

Set appRef = CreateObject("Photoshop.Application")
jsCode = Array(_
    "var inFolder = Folder.selectDialog('Select a folder to process');",_
    "if(inFolder != null){",_
    "  var fileList = inFolder.getFiles(/.(jpg|jpeg|tif|)$/i);",_
    "  var outFolder = new Folder(decodeURI(inFolder) + '/Edited');",_
    "  if (outFolder.exists == false) outFolder.create();",_
    "  for(var i = 0 ;i < fileList.length; i++){",_
    "    var doc = open(fileList[i]);",_
    "    doc.flatten();",_
    "    var docName = fileList[i].name.slice(0,-4);",_
    "    var saveFile = new File(decodeURI(outFolder) + '/' + docName + '.png');",_
    "    SavePNG(saveFile);",_
    "    activeDocument.close(SaveOptions.DONOTSAVECHANGES);",_
    "  }",_
    "}",_
    "function SavePNG(saveFile){",_
    "  pngSaveOptions = new PNGSaveOptions();",_
    "  pngSaveOptions.embedColorProfile = true;",_
    "  pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;",_
    "  pngSaveOptions.matte = MatteType.NONE;",_
    "  pngSaveOptions.quality = 1;",_
    "  pngSaveOptions.PNG8 = false;",_
    "  pngSaveOptions.transparency = true;",_
    "  activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);",_
    "}")
appRef.DoJavaScript(Join(jsCode, vbNewLine))

我的问题是:我可以使用FolderFile类直接从我的VB脚本?比如:

Set psFolder = appRef.Folder
inputFolder  = psFolder.selectDialog("Select a folder to process")
当我尝试这个,appRef.Folder返回这个错误:

对象不支持此属性或方法

在VBscript中,您可以使用FileSystemObject访问文件夹:

'1.a - user browse for folder
Set objShell  = CreateObject( "Shell.Application" )
Set objFolder = objShell.BrowseForFolder( 0, "Select Folder", 0, myStartFolder )
'1.b - or use a fixed one
sFolder = "C:fooanyFolder"
Set fs = CreateObject("Scripting.FileSystemObject")
Set objFolder = fs.GetFolder(sFolder)
'parse the content of the folder
Set oChildren = objFolder.SubFolders
ReDim aList(oChildren.Count)
For i = 1 To oChildren.Count
    aList(i) = oChildren.Item(i).Name
Next

相关内容

  • 没有找到相关文章

最新更新