Creative Communities of the World Forums

The peer to peer support community for media production professionals.

  • Posted by Saransh Sharma on October 1, 2021 at 1:59 pm

    Hi,

    I am writing a script to move photoshop files into a specific folder but I have to press the button several times for it to move all the photoshop files. I want the function to move all the photoshop files into the folder in one click and not several. Any help is much appreciated. Below is the code –

    movepsd.onClick = function (){
    var psdFolder = null;
      for (var i = 1; i <= app.project.numItems; i++){
        if ((app.project.item(i) instanceof FolderItem) && (app.project.item(i).name == "psd")){
            
          psdFolder = app.project.item(i);
          break;
        }
      }
    
      if (psdFolder == null) return;
    for(var i = 1; i <= app.project.numItems; i++){
        var splitName = app.project.item(i).name.split(".");
        if((app.project.item(i) instanceof FootageItem) && (splitName[splitName.length-1].toLowerCase() == "psd") || (splitName[splitName.length-1].toLowerCase() == "PSD"))
          app.project.item(i).parentFolder = psdFolder;
    }
    }

     

    Thanks,

    Andrei Popa replied 4 years, 11 months ago 2 Members · 1 Reply
  • 1 Reply
  • Andrei Popa

    October 2, 2021 at 6:09 am

    The problem here is that you are moving items in your project while looping through them. You need first to save them into an array then loop through that array. Try this:

    movepsd.onClick = function () {

    var psdFolder = null;

    for (var i = 1; i <= app.project.numItems; i++) {

    if (

    app.project.item(i) instanceof FolderItem &&

    app.project.item(i).name == "psd"

    ) {

    psdFolder = app.project.item(i);

    break;

    }

    }

    if (psdFolder == null) return;

    var projItems = [];

    for (var i = 1; i <= app.project.numItems; i++) {

    projItems.push(app.project.item(i));

    }

    for (var i = 0; i < projItems.length; i++) {

    var splitName = projItems[i].name.split(".");

    if (

    (projItems[i] instanceof FootageItem &&

    splitName[splitName.length - 1].toLowerCase() == "psd") ||

    splitName[splitName.length - 1].toLowerCase() == "PSD"

    )

    projItems[i].parentFolder = psdFolder;

    }

    };

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy