How can I return true if a file containing "20180820" as a file name exists in the directory and return false if it does not exist?

Telling me about sample code and ideas.

Thank you.

  • Answer # 1

    First, calculate the "Ruby folder" and execute the instruction whether the file exists there

    If you ask for it with #ruby, I think it will come out with "ruby file existence confirmation"

  • Answer # 2

    reference information

    I want to output all files in the Ruby directory

    [Complete coverage] Ruby directory and file operation summary (dir, file)

    Once you have a list of file names, the next step is to determine if each contains"20180820" ;. If you find one that contains at least one, you can set it to true.

  • Answer # 3

    No need for Ruby. Yes, shell art!

    $find. -type f -name '* 20180820 *' -print -quit | awk 'END {print NR? "true": "false"}'

  • Answer # 4

    Use theDir.globmethod.