JSFL Rename Folder
JSFL does not have a method to rename a folder, which means you have to create a new folder with the new name, copy all the contents of the old folder into the new one, and then delete the old folder. It's a bit of a pain.
Here is the JSFL code to do this until Adobe sees fit to add a rename folder method. You can also use this to move a folder from one place to another.
function renameFolder(sourcePath, targetPath) { FLfile.createFolder(targetPath); copyFolders(sourcePath, targetPath, FLfile.listFolder(sourcePath, "directories")); copyFiles(sourcePath, targetPath, FLfile.listFolder(sourcePath, "files")); FLfile.remove(sourcePath); } function copyFolders(sourcePath, targetPath, folderList) { var i = folderList.length; while (i--) { FLfile.createFolder(targetPath + "/" + folderList[i]); copyFiles(sourcePath + "/" + folderList[i], targetPath + "/" + folderList[i], FLfile.listFolder(sourcePath + "/" + folderList[i], "files")); copyFolders(sourcePath + "/" + folderList[i], targetPath + "/" + folderList[i], FLfile.listFolder(sourcePath + "/" + folderList[i], "directories")); } } function copyFiles(sourcePath, targetPath, fileList) { var i = fileList.length; while (i--) { FLfile.copy(sourcePath + "/" + fileList[i], targetPath + "/" + fileList[i]); } }
Posted in JSFL, Tips/Tricks
June 14th, 2008 at 7:21 am
Thanks for the great JSFL help on your blog! Is it also possible to convert layers to a movieclip?
I have about 1200 layers, on each layer 1 group.. and i like to convert each layer / group to a movieclip.
Thanks in advance,
Tim.
July 15th, 2008 at 12:04 pm
Actually, there are a couple of JSAPIs that can rename folders, but the UI doesn't get updated right away.
You can use either of these:
fl.getDocumentDOM().library.renameItem("new name");
var selItems = fl.getDocumentDOM().library.getSelectedItems();
var item0 = selItems[0];
item0.name = 'foo';
fl.trace('item name: ' + item0.name);
The name will be changed, but will not appear to be until you force a library refresh, e.g. by adding or renaming another item or updating use counts.
July 15th, 2008 at 12:08 pm
Oops, I didn't really read your code before replying. I just assumed you were talking about library folders.
September 21st, 2008 at 8:02 am
I'm trying to achieve, in my world a very simple task, of adding a (very large) selection of 'groups' to the library and edit them one by one (adding a layer, draw a rectangle).
I can convert the symbols fine. I can enter edit mode just fine. I can add a layer just fine. And I can draw a rectangle just fine.
My problem is that the added rectangle is placed in the top left corner of the stage, and not the top left corner of the symbol. And how do I specify the rectangle to the width and height of the symbol itself addNewRectangle({left:0, top:0, right: width, bottom: height}, 0)?
Sorry, if this is not the place to ask things like this, but I've been fighting this for days, and can't seem to find anywhere else to go on Google.