I need some help about keywords searching in directory and files.
I have a directory
dirs--a
>--b
>--c
and files
a-->a1.txt
>-->a2.txt
>-->a3.txt
I can lsit all files and directories like this,
require 'find'
dirs = ['C:\\Users\\test\\dirs']
keywords = ["keyword1","keyword2"]
for dir in dirs
Find.find(dir) do |path|
if FileTest.directory?(path)
if keywords.include?(File.basename(path))
# make something here... and output the finding data
else
Find.prune # skip the files
next
end
else
puts path
end
end
end
how can I do it and how can I print output the results in a text or csv
file?
Or need a plugin like Ferret?
please help me.
···
--
Posted via http://www.ruby-forum.com/.
Ahmet Kilic wrote:
I need some help about keywords searching in directory and files.
I have a directory
dirs--a
>--b
>--c
and files
a-->a1.txt
>-->a2.txt
>-->a3.txt
I can lsit all files and directories like this,
require 'find'
dirs = ['C:\\Users\\test\\dirs']
keywords = ["keyword1","keyword2"]
for dir in dirs
Find.find(dir) do |path|
if FileTest.directory?(path)
if keywords.include?(File.basename(path))
# make something here... and output the finding data
else
Find.prune # skip the files
next
end
else
puts path
end
end
end
how can I do it and how can I print output the results in a text or csv
file?
Or need a plugin like Ferret?
please help me.
To write to a file you need something like this:
f=File.new("w","myfile.txt")
f << "line 1"
f << "line 2"
f.close
···
--
Posted via http://www.ruby-forum.com/\.
To write to a file you need something like this:
f=File.new("w","myfile.txt")
f << "line 1"
f << "line 2"
f.close
Sorry it should be filename, mode ..this way is the correct.
f=File.new("myfile.txt","w)
···
--
Posted via http://www.ruby-forum.com/\.
Rodrigo Bermejo wrote:
To write to a file you need something like this:
f=File.new("w","myfile.txt")
f << "line 1"
f << "line 2"
f.close
Sorry it should be filename, mode ..this way is the correct.
f=File.new("myfile.txt","w)
It is OK. Thank you very much.
I don't want to print the whole line,
I want to print some sql special words,
for example;
1- if the line start with comment(//) do not print the line.
2- if line contain "find" and I want to print the leftside of "::" or
class name (like this ClassBase::Class print ClassBase)
3- if line contain "find" and I want to print the sql commands (like
insert update ...), table and column names. ( like this; insert into
tableA where
columnA, columnB, columnC... print he TableA and ColumnA, columnB,
columnC ...)
please help me.
···
--
Posted via http://www.ruby-forum.com/\.
Ahmet Kilic wrote:
Rodrigo Bermejo wrote:
To write to a file you need something like this:
f=File.new("w","myfile.txt")
f << "line 1"
f << "line 2"
f.close
Sorry it should be filename, mode ..this way is the correct.
f=File.new("myfile.txt","w)
It is OK. Thank you very much.
I don't want to print the whole line,
I want to print some sql special words,
for example;
1- if the line start with comment(//) do not print the line.
2- if line contain "find" and I want to print the leftside of "::" or
class name (like this ClassBase::Class print ClassBase)
3- if line contain "find" and I want to print the sql commands (like
insert update ...), table and column names. ( like this; insert into
tableA where
columnA, columnB, columnC... print he TableA and ColumnA, columnB,
columnC ...)
please help me.
what I done so far;
1- i think it OK.
2- It almost done but I can do print it with this code
text[/(D.*)+::/], if the line contains second :: it print also. I
dontwant it.
3- maybe 50 percent, i can print
text.grep( /FROM\s+(.*?)\s+WHERE/ ) do |line|
puts line
end
but it is not what I want.
please help me!...
···
--
Posted via http://www.ruby-forum.com/\.