Skip to content

Instantly share code, notes, and snippets.

@madmas
Created September 19, 2011 08:37
Show Gist options
  • Save madmas/1226153 to your computer and use it in GitHub Desktop.
Save madmas/1226153 to your computer and use it in GitHub Desktop.
groovy script: loop through subdirs and write file info to mysql database
#!/usr/bin/env groovy
import groovy.sql.Sql
def sql = Sql.newInstance("jdbc:mysql://localhost/statistics", "user",
"password", "com.mysql.jdbc.Driver")
File f = new File(".");
f.eachDir { dir ->
dir.eachFile { file ->
sql.executeInsert("INSERT INTO db (week, db, size) VALUES (${dir.getName()}, ${file.getName()}, ${file.size()})")
println dir.getName() + " " + file.getName() + " " + file.size()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment