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.