Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Remove parent folder and all subfolders (custom info panels)

Community Expert ,
Jan 11, 2012 Jan 11, 2012

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+'/bin').getFiles());

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

for (var i = 0; i < xRemove.length; i++) var xRes = (Folder (xRemove+'/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).remove();

    //Loop through array of loc files and remove them

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

    // Loop through array of resource files and remove them

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

    // remove manifest file

    for (var i = 0; i < xRemove.length; i++) File(xRemove+'/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+'/bin').remove();

// Remover now empty loc folder

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

// Remove now empty resources folder

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

// Remove now empty old version folder

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

}  

Thanks for your help,

Greg Reser

TOPICS
Scripting
960
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2012 Jan 26, 2012
LATEST

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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines