[Ruby] IBM's search method of choice 05-10-2015, 09:22 PM
#1
I was clicking around, trying to find stuff to add to Envoy (big update on the way) and I found this on IBM's site. It's fairly basic, but it works like a charm (usable cross-platform, no Gems needed).
Code:
require 'find'
puts ""
puts "-----------------------File Search-----------------------------------"
puts ""
print "Enter the search path : "
path = gets
path = path.chomp
puts ""
print "Enter the search pattern : "
pattern = gets
pattern = pattern.chomp
puts"----------------------------------------------------------------------"
puts "Searching in " + path + " for files matching pattern " + pattern
puts"----------------------------------------------------------------------"
puts ""
Find.find(path) 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
endIt's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.
don't have much in the first place, who feel the new currents and ride them the farthest.















![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)