From: Hassan Schroeder Date: 2013-05-06T08:20:23+09:00 Subject: Re: Files management with Ruby On Sun, May 5, 2013 at 1:47 PM, sdsd asda wrote: > So where I am at is, I am trying to write a method first to just loop > through Directory A and just add some text to the file called "Today". > This is not working below. Can anyone tell me where I am going wrong? The first thing wrong is not defining EXACTLY what you mean by "not working". However, possible 'errors': > def append_data_to_daily_files > Dir.entries('A').each do |file| > next if !(file.match(/today/)) 1. Are you trying to match "Today" or "today"? 2. Not an error, but more idiomatic (and readable): next unless file.match /today/ 3. That will also match e.g. 'potatodaytime' or 'Platodaylight' -- is that acceptable? Maybe you just want a simple equality check? > File.open(file, 'w') {|file| 4. Opening a file to "write" creates a zero-length file, so your content will *not* be appended, it will replace what was there before. > file.write("hello") > file.close} 5. The file.close is redundant; it's closed when the block passed to File.open ends. HTH, -- Hassan Schroeder ------------------------ hassan.schroeder@gmail.com http://about.me/hassanschroeder twitter: @hassan