From: Chad Perrin Date: 2011-08-19T05:53:45+09:00 Subject: Re: Searching in a directory --X1bOJ3K7DJ5YkBrT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 19, 2011 at 05:47:52AM +0900, Yu Yu wrote: > First of all thank you very much for help. I want to search in all .txt= =20 > files of a folder for a string and when I find this string, then i call= =20 > a function_1. If there's no string, I call a function_2. Later the=20 > string will be dynamic, but that's not important now. I took the code=20 > from Josh and tried a bit, but there's still a mistake concerning=20 > reading the whole file. >=20 > Dir["**/*.txt"].each do |filename| > if > File.readlines(filename).include?("123"+"string") then This line, as written, is equivalent to saying: File.readlines(filename).include?("123string") then Is that what you intended? > puts("function_1") Are you trying to call a method called function_1 or are you just trying to output the string "function_1"? > else > puts("function_2") > end > end --=20 Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] --X1bOJ3K7DJ5YkBrT Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) iEYEARECAAYFAk5Nd5oACgkQ9mn/Pj01uKXGlACfXH1/hobipdXrtj4b0azSBske XbEAn0oYT0uqzeafVb7j3SwNQm/JRGlv =B51Y -----END PGP SIGNATURE----- --X1bOJ3K7DJ5YkBrT--