extendscript系统文件夹检查

时间:2015-05-19 21:26:53

标签: javascript directory exists extendscript

我正在尝试构建一个有助于组织的对话框。基本上,它从我们的项目文件夹中提取所有文件夹并对其名称进行排序并将它们放入下拉列表中。然后,用户将选择他们正在处理的任何项目,输入他们的姓名首字母,添加简短描述,然后最后添加版本号001.我已经在下面的脚本中看起来一切正常。一个例子是

XXXPROJECTNAME_XXXINTIALS_XXXDESCRIPTION_001.aep

/Volumes/Nacho/Multimedia/PROJECTS/ABC_123_Teaser/01_AE/DW/ABC_123_Teaser_DW_TEST_001.aep

我们将它放在文件结构中的initialed文件夹中,所以 /Volumes/Nacho/Multimedia/PROJECTS/ABC_123_Teaser/01_AE/DW

我需要帮助的是检查文件夹是否已经存在,如果没有,则创建文件夹。我总是知道文件夹应该在哪里(/ Volumes / Nacho / Multimedia / PROJECTS / ABC_123_Teaser / 01_AE / DW),所以我需要一种方法来检查另一个被调用文件夹数组。我觉得我的逻辑是稳固的,但编码技巧不是。

如果文件夹存在,我们需要检查并查看该文件夹中是否已存在文件名。如果没有,则使用当前名称保存,但如果确实存在,则从001增加到002。

超级奖励积分,如果任何人都可以解释如何在文件夹列表排序时使进度条工作。我有大约125个文件夹,它排序大约需要7秒。我现在拥有它的方式,进度条大约7秒钟完成它的事情,然后列表再排序7秒。目前,进度条是我最少的问题。

win=new Window("palette","AE Naming",[0,0,525,60],{resizeable:true,});
panel_1=win.add("panel",[5,5,525,57]);
downlist_1=panel_1.add("dropdownlist",[5,25,185,46] ,["PROJECT LIST"]);
edittext_1=panel_1.add("edittext",[190,25,250,45] ,"INITIALS",{readonly:0,noecho:0,borderless:0,multiline:0,enterKeySignalsOnChange:1});
edittext_2=panel_1.add("edittext",[255,25,380,45] ,"DESCRIPTION",{readonly:0,noecho:0,borderless:0,multiline:0,enterKeySignalsOnChange:1});
edittext_3=panel_1.add("edittext",[385,25,435,45] ,"001",{readonly:0,noecho:0,borderless:0,multiline:0,enterKeySignalsOnChange:1});
edittext_4=panel_1.add("edittext",[5,2,435,22] ,"FULL PATH NAME",{readonly:1,noecho:0,borderless:0,multiline:0,enterKeySignalsOnChange:1});
but_1=panel_1.add("button",[440,2,510,45],"SAVE");
progress_1=panel_1.add("progressbar", [5,0,510,5], 0, 100);

win.center();
win.show();

but_1.onClick = function() {
                        save();
                    }
{

var layerNameArray = new Array();    
var myFolder = Folder("/Volumes/Nacho/Multimedia/PROJECTS/"); //Search for all Folders in the projects directory
var myJPGFilesArray = myFolder.getFiles(function(f) {return f instanceof Folder});


if(myJPGFilesArray !== null){  
for(var n=0; n<myJPGFilesArray.length;n++){  
    $.writeln(myJPGFilesArray[n].name);  
var test = myJPGFilesArray.toString().replace (new RegExp("%20", "g"), " "); //removes the %20 which are spaces
     layerNameArray.push(myJPGFilesArray[n].name); //adds Folders to the Array
var sortMe = myJPGFilesArray.sort(); //Alphabetical sort

//////////////PROGRESSBAR ESTIMATED TIME//////////////
    while(progress_1.value < progress_1.maxvalue)
    {
        // this is what causes the progress bar increase its progress
        progress_1.value++; 
        $.sleep(35); //35 is about 7 seconds
    }
    $.writeln("Sorting Complete");
///////////////////////////////////////////////////////

     downlist_1.add("item", sortMe[n].name); //Adds sorted Folders to the dropdownlist

downlist_1.onChange = function () {(downlist_1.selection)}
edittext_1.onChanging = function () {(edittext_1.text)}
edittext_2.onChanging = function () {(edittext_2.text)}
edittext_3.onChanging = function () {(edittext_3.text)}

 function save() {

//var combined = ("Volumes/Nacho/Multimedia/PROJECTS/" + downlist_1.selection + "/01_AE/" + edittext_1.text + "");
var aa = downlist_1.selection.toString(); //PROJECT
var bb = edittext_1.text.toString(); //INITIALS
var cc = edittext_2.text.toString(); //DESCRIPTION
var dd = edittext_3.text.toString(); //VERSION
var ae = "/01_AE/"; //where intials fodler should live
var slash = "/"
var underscore = "_"
var aep = ".aep"
var macVolume = "/Volumes/Nacho/Multimedia/PROJECTS/";
var folderpath = macVolume+aa+ae+bb;
var fullpath = macVolume+aa+ae+bb+slash+aa+underscore+bb+underscore+cc+underscore+dd+aep;

edittext_4.text = fullpath;
alert(folderpath);
alert(fullpath);

//Check to see if folder in folder path exists. if it does continue on. if it doesn't create a new folder.

//Check to see if the file name.aep exitsts AKA fullpath. If it does exist then version up. 001 becomes 002.  If not, just save as fullpath.

}
}
}
}

我知道解决方案可能非常简单,但我仍然对所有这些都很新,包括Javascript和Extendscript,所以有时候最简单的事情是最容易忽视的。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

可能就像

一样简单
if (!Folder(folderpath).exists)
  Folder(folderpath).create();

while (File(fullpath).exists)
{
   dd = "000"+String(Number(dd)+1);
   dd = dd.substring(dd.length-3);
   fullpath = macVolume+aa+ae+bb+slash+aa+underscore+bb+underscore+cc+underscore+dd+aep;
}

folderpath似乎不会在您当前的代码中使用;我想它会在你的最终代码中填入fullpath

实际上,如果ddNumber(dd)并且所有版本都存在,那么999的3位数格式可能会导致无限循环。您可能希望将此考虑在内现在或在一段时间内遭受后果;)