brabuhr
12/24/2008 4:16:00 PM
On Wed, Dec 24, 2008 at 10:53 AM, Tim Hunter <TimHunter@nc.rr.com> wrote:
> Bob Smith wrote:
>>
>> I am attempting to open a directory, open each file and send each line
>> of the file to a network host...
>>
>> dir = Dir.open(INDIR)
>> dir.each do |f|
>> file = File.open(f,"r")
>
> The filenames returned by dir.each are just filenames, not the complete
> paths. You may need to prepend the INDIR directory name to the filenames to
> get a complete path to open.
Another possible option might be something like:
Dir.glob("#{INDIR}/*").each do |filename|
File.open(filename, "r") do |file|
#...
end
end
glob does return the full path to the file.
Or, possibly something like this could work:
Dir.chdir(INDIR) do
Dir.foreach(".") do |filename|
#...
end
end