使用 "like" 通配符匹配文件名

Matching a file name using "like" wildcards

我正在尝试使流程自动化,但想让它更高效、更智能。我每天自动从我的邮箱下载一个文件,邮箱的命名约定如下:

pending_file_"current_date".xlsx(current_date 为 mmddYYYY,即 pending_file_12082015.xlsx)

正如预期的那样,这个文件夹将变得越来越大,其中包含大量名称非常相似的文件,标题中只有一个变化,在这种情况下,变化将是当前日期。

我正在尝试确保抓取与当天对应的文件,这是我目前所拥有的:

cd Pending_File
date=$(date.exe +"%m%d%Y") #assigns the current date to the date variable in the form of mmddYYYY

if [[ -f *"$date"* ]]; then
    scp pending_file_"$date".xlsx example@sample;
    echo "I have successfully completed today's file!"
else
    echo "Could not find today's file!"
fi

目前,如果我执行我的代码,它总是执行 else 语句,即使我的 pending_file 文件夹包含名为 pending_file_"current_date".xlsx 的文件。我的期望是 date=12082015,它也包含在文件 pending_file_12082015 中,因此 if 语句将 return true 为 [ -f "$date" ] 能够匹配文件名中的日期字符串。

这会起作用:

if [[ -f "pending_file_${date}.xlsx" ]]; then 
   scp ...
fi

同样如此:

for f in *$date*; do 
   scp "$f" ...
done