JavaScript使用Adobe PhotoShop CS4 scripting提供了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))


我的问题是:我可以直接从VB脚本中使用FolderFile类吗?
就像是:

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:\foo\anyFolder\"
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

关于javascript - 如何在VBScript中引用Photoshop文件夹对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15938658/

10-12 17:39