user2836292
user2836292

Reputation: 305

Using Ruby to find a file with changing directory

I'm trying to find a file in which the directory will change its name with upcoming versions, so an example could be that it is located under /opt/here/test-1.44/bin/progname and will follow the format same time.

I'm looking to do something like if File.exist?("/opt/here/test-*/bin/progname") but is that the correct format? When searching around I'm also seeing references to using Dir, so would it be something like if Dir['/opt/here/*'.select { |f| f =~ /progname/} then ?

Thanks!

Upvotes: 1

Views: 59

Answers (1)

sawa
sawa

Reputation: 168081

Do

Dir.glob("/opt/here/test-*/bin/progname").empty?

Use any? instead of empty? if you want true when there is such file.

Upvotes: 3

Related Questions