Skip to content

Instantly share code, notes, and snippets.

@osima
Created September 11, 2010 08:06
Show Gist options
  • Save osima/574976 to your computer and use it in GitHub Desktop.
Save osima/574976 to your computer and use it in GitHub Desktop.
htm,html の拡張子をもったファイル全部列挙
//
// htm,html の拡張子をもったファイル全部列挙.
// さらに title 要素を調べる.
//
import java.util.regex.*
class Util {
def fff = { it.isFile() && (it.name.endsWith('.htm') || it.name.endsWith('.html') ) } as FileFilter
def ffd = { it.isDirectory() } as FileFilter
def recur = { dir->
dir.listFiles(fff).each{ htmllist.add(it) }
dir.listFiles(ffd).each{
recur( it )
}
}
def htmllist
def proc(){
this.htmllist = []
recur( new File('.') )
this.htmllist
}
}
new Util().proc().each{ file->
def enc = 'UTF-8'
def rlist=[]
file.newReader(enc).each{
def r = '<title>(.*)</title>'
def p = Pattern.compile(r)
def m = p.matcher(it)
if( m.find() ){
def t = m.group(1)
println t
}
}
}
//
// htm,html の拡張子をもったファイル全部列挙.
//
class Util {
def fff = { it.isFile() && (it.name.endsWith('.htm') || it.name.endsWith('.html') ) } as FileFilter
def ffd = { it.isDirectory() } as FileFilter
def recur = { dir->
dir.listFiles(fff).each{ println it }
dir.listFiles(ffd).each{
recur( it )
}
}
def proc(){
recur( new File('.') )
}
}
new Util().proc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment