php检查文件是否存在:仅检查部分

Jam*_*lle 1 php file-exists

在php中我们可以检查文件是否存在使用

if(file_exists("destination/"))
{
    condition
}
Run Code Online (Sandbox Code Playgroud)

但我想做的是......

例如,我已经在我的目的地上有这个文件

hello_this_is_filename(2).doc
Run Code Online (Sandbox Code Playgroud)

如何知道该目录中是否有一个名称包含字符的文件

hello_this_is_filename
Run Code Online (Sandbox Code Playgroud)

我想搜索那种方式,因为...如果该目录中存在,我将做的是...将文件重命名为

hello_this_is_filename(3).doc
Run Code Online (Sandbox Code Playgroud)

我还需要计算我搜索的存在,所以我知道我要用的是什么号码

(3), (4), (5) and so on
Run Code Online (Sandbox Code Playgroud)

任何帮助?

xda*_*azz 5

使用glob.

if (count(glob("destination/hello_this_is_filename*.doc"))) {
  //...
}
Run Code Online (Sandbox Code Playgroud)