使用通配符检查文件是否存在 [英] Check if a file exists using a wildcard
本文介绍了使用通配符检查文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Ruby 中,如何使用通配符检查文件是否存在?
In Ruby, how can I check if a file exists using a wildcard?
显然这似乎不起作用:
File.exists?("/folderOfFile/Filename*.ext")
推荐答案
您的通配符将引用一组文件,而不是单个文件.你可以使用 Dir::glob
为此:
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?
这篇关于使用通配符检查文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文