6 Replies Latest reply on Mar 31, 2015 2:13 PM by beh_gras_beh

    Delete all images from chosen path

    beh_gras_beh Level 1

      Dear Indesign scripters,

       

      I have this script to delete all the images.

      Works great, but I wonder it can delete only the images from an specific path?

      The path is /Volumes/Fotosource

      Thats the path from a Mac.

       

      var doc = app.activeDocument;  
      var graphics = doc.allGraphics;  
        
      for (var i = graphics.length-1; i >= 0; i--) {  
           try {  
                graphics[i].remove(); // delete only image  
                // graphics[i].parent.remove(); // delete image and its containing frame  
           }  
           catch (err) {}  
      }  
      

       

      Thanks for the help.

        • 1. Re: Delete all images from chosen path
          Vamitul Level 4

          check the graphic's itemLink property.

          It will give you a Link object (InDesign ExtendScript API (10.0)) that has a filePath property... you can take it from there i think?

          • 2. Re: Delete all images from chosen path
            beh_gras_beh Level 1
            var doc = app.activeDocument;    
            var graphics = doc.allGraphics;    
                
            for (var i = graphics.length-1; i >= 0; i--) {    
                 try {    
                      graphics[i].itemLink.filePath.remove("Volumes/Fotosource"); // delete only image    
                      // graphics[i].itemLink.filePath.remove("Volumes/Fotosource"); // delete image and its containing frame    
                 }    
                 catch (err) {}    
            }   
            

             

             

            Like this?

            • 3. Re: Delete all images from chosen path
              Vamitul Level 4

              certainly not.

              More like:

              var doc = app.activeDocument;      
              var graphics = doc.allGraphics;      
                    
              for (var i = graphics.length-1; i >= 0; i--) {      
                   try {
                    if (graphics[i].itemLink.filePath.fullName.indexOf('/Volumes/Fotosource')>-1){      
                        graphics[i].remove(); // delete only image      
                        }  
                   }      
                   catch (err) {}      
              }
              
              • 4. Re: Delete all images from chosen path
                beh_gras_beh Level 1

                Hmm,

                 

                That's not it, but maybe the path isn't correct, I will look in to this.

                 

                Thanks anyway!

                • 5. Re: Delete all images from chosen path
                  Laubender Adobe Community Professional & MVP

                  Checkhow the path is written as a string on a Mac.

                  You can do it by selecting an image container of an image and read-out the file path.

                   

                  app.selection[0].graphics[0].itemLink.filePath;
                  

                   

                  It will return something like this (just an example):

                  MB-2:CC LibraryIssue with TIFF files:ProductShot-CMYK.tif

                  Where MB-2 is the name of the volume where the folder CC LibraryIssue with TIFF files is located.

                   

                  The following:

                   

                  app.selection[0].graphics[0].itemLink.filePath.fullName;
                  

                   

                  will return "undefined"

                   

                  This one:

                   

                  File(app.selection[0].graphics[0].itemLink.filePath).fullName;
                  

                   

                  will return the representation you'd like to work with (perhaps):

                  /CC LibraryIssue with TIFF files/ProductShot-CMYK.tif

                   

                   

                  Uwe

                  • 6. Re: Delete all images from chosen path
                    beh_gras_beh Level 1

                    Sorry guy's,

                     

                    Forgot to klick on the button "right answer"!

                    P.s. got this now:

                     

                    var doc = app.activeDocument;        
                    var links = doc.allGraphics;  
                    
                    
                    for(var i=links.length-1;i>=0;i--)  
                    {  
                            if(links[i].itemLink.filePath.indexOf('HD:Users:n:Desktop')>-1)
                            {  
                                    links[i].remove()
                                }  
                    
                    
                        }