javascript 如何使用 ExtendScript 创建文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18339060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 11:32:46  来源:igfitidea点击:

How do I create a folder using ExtendScript?

javascriptdirectoryadobe-indesignextendscriptcreate-directory

提问by Sturm

This seemslike it would be a very easy problem to solve, but I've been banging my head against it for almost an hour. All I need is a snippet of javascript/extendscript code so that my InDesign CS6 script can create a folder. I know the existing folder in which the new one should be created, and I know the name that this new folder should be called. But how do I get javascript to doit?

似乎是一个很容易解决的问题,但我已经用头撞了将近一个小时。我所需要的只是一段 javascript/extendscript 代码,以便我的 InDesign CS6 脚本可以创建一个文件夹。我知道应该在其中创建新文件夹的现有文件夹,并且我知道应该调用这个新文件夹的名称。但是我如何让javascript来做到这一点?

By the way, all searches online for the folderObj.create() method, which is in the JavaScript Tools Guide, prove useless. I've tried several variations on that method, but nothing seems to actually create the folder. What am I missing?

顺便说一句,所有在网上搜索 JavaScript 工具指南中的 folderObj.create() 方法都证明是无用的。我已经尝试了该方法的几种变体,但似乎没有实际创建文件夹。我错过了什么?

采纳答案by Sturm

Okay, found a work-around: I have to specify the folder absolutely, rather than use the ~home shortcut. In addition, I have use /Volumesat the very beginning. Thus, the code becomes:

好的,找到了解决方法:我必须绝对指定文件夹,而不是使用~主页快捷方式。另外,我/Volumes一开始就有用。因此,代码变为:

var f = new Folder("/Volumes/apache HD/Users/apache/Desktop/my_new_fodler");  
f.create();

And thatseems to work, finally. Thanks for your help, @Anna Forrest and @fabiantheblind! (You seem to be the resident ExtendScript expert around here.)

似乎工作,终于。感谢您的帮助,@Anna Forrest 和@fabiantheblind!(您似乎是这里的常驻 ExtendScript 专家。)

回答by Anna Forrest

    var f = new Folder('/c/myfolder/');
    if (!f.exists)
        f.create();

回答by fabianmoronzirfas

try this:

试试这个:

var f = new Folder("~/Desktop/my_new_fodler");  
f.create();