Created
September 19, 2011 08:37
-
-
Save madmas/1226153 to your computer and use it in GitHub Desktop.
groovy script: loop through subdirs and write file info to mysql database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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