Sinisterly
[Ruby] IBM's search method of choice - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Coding (https://sinister.ly/Forum-Coding--71)
+--- Thread: [Ruby] IBM's search method of choice (/Thread-Ruby-IBM-s-search-method-of-choice)



[Ruby] IBM's search method of choice - Inori - 05-10-2015

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



RE: [Ruby] IBM's search method of choice - ring-1 - 05-11-2015

where would this rb script be useful for anything practical


RE: [Ruby] IBM's search method of choice - Inori - 05-11-2015

(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).


RE: [Ruby] IBM's search method of choice - ring-1 - 05-11-2015

(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


RE: [Ruby] IBM's search method of choice - Inori - 05-11-2015

(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.


RE: [Ruby] IBM's search method of choice - ring-1 - 05-11-2015

(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


RE: [Ruby] IBM's search method of choice - Jolly - 05-27-2015

path = gets
path = path.chomp

Why not just:
path=gets.chomp

Isn't it faster that way?


RE: [Ruby] IBM's search method of choice - Inori - 05-27-2015

(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.