1 Reply Latest reply: Jan 26, 2012 7:42 PM by gregreser RSS

    Remove parent folder and all subfolders (custom info panels)

    gregreser Community Member

      I'm writing a script to help users install custom info panels in the Folder.userData + '/Adobe/XMP/Custom File Info Panels/3.0/panels' location.  I have a working script to copy files, but I also want to delete previous versions of the same info panel.   I also want to allow for the possibility that could be several older versions so I need to loop through them.  I know that I need to empty the files of a folder before it can be removed.  I can remove one instance of a ninfo panel, but not several - I'm having trouble getting the function to loop.

       

      For example, if I have two old info panel version to delete (myPanel_v1 and myPanel_v2) can use getFiles (myPanel*) to get an array with the names of the two parent folders:

      ~/AppData/Roaming/Adobe/XMP/Custom%20File%20Info%20Panels/3.0/panels/myPanel_v1,~/AppData/ Roaming/Adobe/XMP/Custom%20File%20Info%20Panels/3.0/panels/myPanel_v2

       

      What I can't do is the loop through the subfolders and their contents based on the index of this array.  Perhaps there is a completey different approach I need to take?

       

       

      The code below does remove a single instance of my custom ino panel, but I can't figure out a way to make it loop.

       

      var CS5panelsFolder = (Folder.userData + '/Adobe/XMP/Custom File Info Panels/3.0/panels');

      var xmask = 'myPanel*'

      var xRemove =  (Folder (CS5panelsFolder).getFiles (xmask));  // returns an array with all folders with 'VRA_beta' in the name

      for (var i = 0; i < xRemove.length; i++) var xBin = (Folder (xRemove[i]+'/bin').getFiles());

      for (var i = 0; i < xRemove.length; i++) var xLoc = (Folder (xRemove[i]+'/loc').getFiles());

      for (var i = 0; i < xRemove.length; i++) var xRes = (Folder (xRemove[i]+'/resources').getFiles());

       

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

      {

          //Loop through array of xBin files and remove them

          for (var i = 0; i < xBin.length; i++) File(xBin[i]).remove();

          //Loop through array of loc files and remove them

          for (var i = 0; i < xLoc.length; i++) File(xLoc[i]).remove();

          // Loop through array of resource files and remove them

          for (var i = 0; i < xRes.length; i++) File(xRes[i]).remove();

          // remove manifest file

          for (var i = 0; i < xRemove.length; i++) File(xRemove[i]+'/manifest.xml').remove();

      }

       

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

      {

      // Remove now empty xBin folder

          for (var i = 0; i < xRemove.length; i++) Folder(xRemove[i]+'/bin').remove();

      // Remover now empty loc folder

          for (var i = 0; i < xRemove.length; i++) Folder(xRemove[i]+'/loc').remove();

      // Remove now empty resources folder

          for (var i = 0; i < xRemove.length; i++) Folder(xRemove[i]+'/resources').remove();

      // Remove now empty old version folder

          for (var i = 0; i < xRemove.length; i++) Folder(xRemove[i]).remove();

      }  

       

       

      Thanks for your help,

       

      Greg Reser

        • 1. Re: Remove parent folder and all subfolders (custom info panels)
          gregreser Community Member

          I now have this code that works:

           

          var W = 'Base Folder Name';

          var X = Folder(W).getFiles();

          for (var Q1 = 0; Q1 < X.length; Q1++)

             {

             if (X[Q1] instanceof Folder == true)

               {

               var Y = Folder (X[Q1]).getFiles();

               for (var Q2 = 0; Q2 < Y.length; Q2++)

                 {

                 if (Y[Q2] instanceof Folder == true)

                   {

                   var Z = Folder (Y[Q2]).getFiles();

                   for (var Q3 = 0; Q3 < Z.length; Q3++) File (Z[Q3]).remove();

                   Folder (Y[Q2]).remove();

                   }

                 else File (Y[Q2]).remove();

                 }

               Folder (X[Q1]).remove();

               }

             else File (X[Q1]).remove();

             }

          Folder(W).remove();