Skip to content

Instantly share code, notes, and snippets.

@timyates
Forked from loverdos/findcmd.scala
Created July 17, 2009 14:10
Show Gist options
  • Save timyates/149068 to your computer and use it in GitHub Desktop.
Save timyates/149068 to your computer and use it in GitHub Desktop.
#!/usr/bin/env groovy
// Trying it in Groovy as a shell script (just for fun)
import java.util.regex.Pattern
// All folders on the path which have contents:
path = System.env[ 'PATH' ]
.tokenize( File.pathSeparator )
.collect( { new File( it ) } )
.findAll { it.directory && it.listFiles() }
args.collect { it.toLowerCase() }.each { name ->
println "--- $name --->"
counter = 0
path.each { folder ->
children = folder.list()
found = children.findAll { child ->
child.toLowerCase().indexOf( name ) > -1
|| Pattern.compile( name, Pattern.CASE_INSENSITIVE ).matcher( child ).find()
}
if( found ) {
if( folder.getAbsolutePath().indexOf( " " ) > -1 ) {
println "\"$folder\":"
}
else {
println "$folder:"
}
println " ${found.join ', '}"
}
counter += found.size
}
println()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment