Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 检查是否存在与regex、glob或通配符模式匹配的文件?_Ruby - Fatal编程技术网

Ruby 检查是否存在与regex、glob或通配符模式匹配的文件?

Ruby 检查是否存在与regex、glob或通配符模式匹配的文件?,ruby,Ruby,我知道File.exists?,但它似乎是用字符串或IO对象操作的。我需要的是能够使用regex、glob或通配符 例如,我想说File.exists?(“/pictures/tank_man.*”),看看是否存在一个名为tank_man的图像,它是否是jpg、tif、png等等。您可以使用Dir[“/pictures/tank_man.*”] 它将返回现有路径谢谢,这太棒了。我不知道迪尔能做到。

我知道
File.exists?
,但它似乎是用字符串或IO对象操作的。我需要的是能够使用regex、glob或通配符

例如,我想说
File.exists?(“/pictures/tank_man.*”)
,看看是否存在一个名为tank_man的图像,它是否是jpg、tif、png等等。

您可以使用
Dir[“/pictures/tank_man.*”]

它将返回现有路径

谢谢,这太棒了。我不知道迪尔能做到。