Skip to content

Instantly share code, notes, and snippets.

@perfectfoolish
Created September 26, 2013 06:24
Show Gist options
  • Save perfectfoolish/6710485 to your computer and use it in GitHub Desktop.
Save perfectfoolish/6710485 to your computer and use it in GitHub Desktop.
require 'find'
puts ""
puts "-----------------------File Search-----------------------------------"
puts ""
print "Enter the search path : "
searchpath = gets
searchpath = searchpath.chomp
puts ""
print "Enter the search pattern : "
pattern = gets
pattern = pattern.chomp
puts"----------------------------------------------------------------------"
puts "Searching in " + searchpath + " for files matching pattern " + pattern
puts"----------------------------------------------------------------------"
puts ""
Find.find(searchpath) do |path|
if FileTest.directory?(path)
if File.basename(path)[0] == ?.
Find.prune # Don't look any further into this directory.
else
next
end
else
if File.fnmatch(pattern,File.basename(path))
puts "Filename : " + File.basename(path)
s = sprintf("%o",File.stat(path).mode)
print "Permissions : "
puts s
print "Owning uid : "
puts File.stat(path).uid
print "Owning gid : "
puts File.stat(path).uid
print "Size (bytes) : "
puts File.stat(path).size
puts "---------------------------------------------------"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment