[英]Find files with certain name but variable file extension
I'd like to be able to select a file by just giving it's name (without extension). 我希望仅通过提供文件名即可选择文件(不带扩展名)。 For example, I might have a variable $id
holding 12
. 例如,我可能有一个变量$id
持有12
。 I want to be able to select a file called the-id-in-the-variable, say, 12.png
from a directory, but it may have any one of a number of file extensions, listed below: 我希望能够从目录中选择一个名为the-id-in-the-variable的文件,例如12.png
,但它可能具有以下列出的许多文件扩展名中的任何一个:
There is only one occurrence of each ID. 每个ID仅出现一次。 I could use a loop and file_exists()
, but is there a better way? 我可以使用循环和file_exists()
,但是有更好的方法吗?
Thanks, 谢谢,
James 詹姆士
Quick question to OP here: 在这里向OP快速提问:
What is the file extension of this file: somefile.tar.gz
? 该文件的文件扩展名是somefile.tar.gz
? Is it .gz
or .tar.gz
? 是.gz
还是.tar.gz
? :) I ask because most would answer this question as .tar.gz
... :)我问,因为大多数人都会以.tar.gz
形式回答这个问题...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.