Michael Küller
Michael Küller

Reputation: 3994

Check if a file exists using a wildcard

In Ruby, how can I check if a file exists using a wildcard?

Apparently this does not seem to work:

File.exists?("/folderOfFile/Filename*.ext")

Upvotes: 34

Views: 17762

Answers (1)

dbenhur
dbenhur

Reputation: 20408

Your wildcard would refer to a set of files, not a single file. You could use Dir::glob for this:

!Dir.glob('/folderOfFile/Filename*.ext').empty?

Upvotes: 66

Related Questions