logger = Logger.new("loggfile.log") # open a logger if you are not inside a controller begin dir = Dir.new("#{RAILS_ROOT}/sampledb") dir.each { |dEntryName| file = File.new(dEntryName) #open the current entry in the directory next unless file.stat.file? # check is this a directory if yes ignore it. myDatabaseTable = MyTable.new() #pass argument to new if any extra columns present in table myDatabaseTable.file_content = file.read # read all contents in file myDatabaseTable.save! } rescue Exception => e logger.error( e.message) #log what ever you want. return false # return if necessary or else forget it end
I guess this solves your problem and i assumed MyTable is table where your going to put your content and column name i assume it as file_content, even you can save the file name inside the database, and (return false may not be necessary.) and also assuming you are using oracle db, and column type for file_content as either varchar2, or blob or which ever is suitable.
Good luck,