rapaul.com

A technical blog written by Richard Paul

Checking Wordpress Images Are Present With Groovy

Below is a little script I knocked up today to ensure all uploaded images referenced in a Wordpress XML export are present on your server. A useful check when moving to a new Wordpress instance.

1
2
3
4
5
6
7
8
def imagePattern = ~'http://www.rapaul.com/wp-content/uploads/.+?/.+?/.+?(jpg|jpeg|png|gif)'
new File('./wordpress-export.xml').text.findAll(imagePattern).each { address ->
   try {
       new URL(address).openStream().close()
   } catch (FileNotFoundException e) {
       println "Could not find $address"
   }
}

I’m sure a bash guru could hack together something similar but Groovy really does make it simple.

Comments