From: "Sönke Buhr" Date: 2011-08-16T02:51:55+09:00 Subject: Re: SFTP grep on foreach 7stud -- wrote in post #1016702: > Sönke Buhr wrote in post #1016662: >> Hi guys, >> >> I got >> >> Net::SFTP.start("somehost", "someuser", :password => "somepwd", >> :keys => []) do |sftp| >> sftp.dir.foreach("/upload/") do |e| >> >> >> >> What I want to do is to only parse the files in this given directory >> which include "findme" and "foundme" for example. >> >> ls -l | grep "findme\|foundme" does the trick in a normal console. >> >> Is there any way to do this via sftp? >> >> Thanks in advance. >> >> Regards > > > How about: > > base_path = "some/path" > > sftp.dir.foreach(base_path) do |entry| > if entry =~ /(found|find)me/ > sftp.file.open("#{base_path}/#{entry}, "r") do |f| > while f.gets > #do something > end > end > end > end Hi, thanks for your reply. I kind of do that already. if %w(my string list).any? {|str| e.name.include? str} My problem is that there are over 30.000 files on this server so my intend was to filter unneeded files with the foreach call. I only have limited access to this server... Keep it up. -- Posted via http://www.ruby-forum.com/.