hello to everyone, i am new to ruby and programming. At the moment i am
a bit confused on how to make a program do what i will explain in the
following lines so please any help will be appreciated!
In a few words, what i want to is to write a script which will parse
many .txt files inside a folder. Each file contains text in the format:
FileID: id
Name1: Value
Name2: Value2
, where the Names remain the same in every file but the Values change
(id is number).
So, the program based on id (number) of each file will handle the file
for example if "id" is "1" it will skip the file.
if "id" is "10" it will process the file.
if "id" is "20" it will process the file.
When each file will be processed the program will have to compare the
other values (Value, Value2 etc) with the values of a database
(MS-Access db containing same values) and if the values are same do
nothing, if not do something else.
A possible solution im thinking may be:
require 'DBI'
# connection with database
cn = DBI.connect('DBI:ODBC:database')
# parsing each file inside the folder
class File_parse
basedir = "C:\filefolder"
Dir.chdir(basedir)
files = Dir.glob("*")
begin
files.each do |file|
result = {}
files.readlines do |lines|
k,v=line.split("=")
result[k.strip]=v.strip
end
but from this point i don't know how to continue, how to compare the
values of each file with the values inside the database..
for example
if result.FileID=1
do nothing
set a flag to false
if result.FileID=10
compare Name1: Value1 with values of database
set a flag to true
if result.FileID=20
compare Name2: Value2 with values of database
set a flag to true
end
if flag = true
do something
else
do nothing
end
my programming skills are very limited so any help or explanations on
how to continue will be much appreciated.
···
--
Posted via http://www.ruby-forum.com/.