Login Register


[Ruby] IBM's search method of choice filter_list
Author
Message
[Ruby] IBM's search method of choice #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 end
It'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.

Reply

RE: [Ruby] IBM's search method of choice #2
where would this rb script be useful for anything practical

Reply

RE: [Ruby] IBM's search method of choice #3
(05-11-2015, 06:09 AM)ring-1 Wrote: where would this rb script be useful for anything practical

If you've tried it, you would know.

It's (probably) a more advanced and in-depth version of your run-of-the mill stock search tool that comes packaged with your OS/distro. It's especially useful for people who want to run a file search in their shell/command line, which can be accomplished by requesting ruby search.rb (if that's what you named the file).
It'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.

Reply

RE: [Ruby] IBM's search method of choice #4
(05-11-2015, 04:05 PM)Touka Wrote: If you've tried it, you would know.

It's (probably) a more advanced and in-depth version of your run-of-the mill stock search tool that comes packaged with your OS/distro. It's especially useful for people who want to run a file search in their shell/command line, which can be accomplished by requesting ruby search.rb (if that's what you named the file).

but if you want to search for a file in a cli shell then you can just use which, find, or for windows, dir
http://unixhelp.ed.ac.uk/CGI/man-cgi?find
http://linux.die.net/man/1/whereis
what do you mean "probably" a more advanced version? you seem dubious if it's an efficient tool or not

Reply

RE: [Ruby] IBM's search method of choice #5
(05-11-2015, 04:52 PM)ring-1 Wrote: but if you want to search for a file in a cli shell then you can just use which, find, or for windows, dir
http://unixhelp.ed.ac.uk/CGI/man-cgi?find
http://linux.die.net/man/1/whereis
what do you mean "probably" a more advanced version? you seem dubious if it's an efficient tool or not

I said probably because I'm somewhat unfamiliar with the complexity of Unix/Linux/whatever search tools.
It'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.

Reply

RE: [Ruby] IBM's search method of choice #6
(05-11-2015, 05:20 PM)Touka Wrote: I said probably because I'm somewhat unfamiliar with the complexity of Unix/Linux/whatever search tools.

ah right fair enough

Reply

RE: [Ruby] IBM's search method of choice #7
path = gets
path = path.chomp

Why not just:
path=gets.chomp

Isn't it faster that way?


[Image: tumblr_noac9s6rgw1tvnnaxo1_500.gif]
Tik Tak~! Time is up~!

Reply

RE: [Ruby] IBM's search method of choice #8
(05-27-2015, 10:54 AM)Jolly Wrote:
Code:
path = gets path = path.chomp
Why not just:
Code:
path=gets.chomp
Isn't it faster that way?

using gets allows for user input without a linebreak, making it look nicer. gets.chomp is more efficient, but I was aiming to tweak design here.
It'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.

[+] 1 user Likes Inori's post
Reply







Users browsing this thread: