Reputation: 13
I am iterating through files in a folder to search for specific string. There is a folder name as persistent.bak. While going through this folder, it is giving error... in 'initialize' : Is a directory @ rb_sysopen - persistent.bak (Errno::EISDIR).
Dir.glob("**/*.*") do |file_name|
fileSdfInput = File.open(file_name)
fileSdfInput.each_line do |line|
if ((line.include?"DATE")
@count = @count + 1
end
end
end
Upvotes: 1
Views: 13290
Reputation: 179
your glob Dir.glob("**/*.*")
matches the pattern persistent.bak
So inside your loop, you're actually trying to open the folder named persistent.bak as a file, which ruby doesn't appreciate.
Just to convince yourself, try to output the file name, you'll see it.
Simplest workaround :
Dir.glob("**/*.*") do |file|
next if File.directory? file
fileSdfInput = File.open(file)
fileSdfInput.each_line do |line|
if (line.include?"DATE")
@count = @count + 1
end
end
end
Upvotes: 5