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")
Option with '*. ' The wildcard '*' means it will match any number of characters or a set of characters. For example, S**n will match anything between S and n.
Use the command -v Command to Check if a Command Exists in Bash. The command -v is a built-in function in all POSIX systems and Bash. This function checks if a command exists as it returns the valid path for that command if it does exist and returns NULL if it does not.
Shopt is a built-in command in Unix-like operating systems, such as macOS and Linux distributions. The “shopt” command provides control over many settings that are used to tweak the operations in a Bash shell.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With