如何验证文件是否符合 PHP 中的掩码而不从磁盘读取文件名
我有一个文件名列表(我已经有文件列表,比如说在文本文件中)。我想按以下方式处理此列表:
- /dirX/subdirX//.ext 类型的文件名将写入一个新文件中,
- 所有其他文件名将写入一个单独的文件中。
是否有任何选项可以验证文件名是否对应于掩码,而无需从磁盘读取文件名?(我所说的文件名是指一个简单的字符串)。我想知道是否有这样的功能,不需要访问磁盘。我知道正则表达式可能是一种解决方法,但我想从 php.ini 获得一些东西。
I have a list of file names(I already have the filelist let's say in a text file). I want to process this list in the following way:
- filenames of type /dirX/subdirX//.ext will be written in a new file
- all the other filenames will be written in a separate file.
Is there any option to verify if a filename corresponds to a mask, without reading the file name from disk?(by filename I mean a simple string). I would like to know if there is such a function that don't require disk access. I know regex could be an workaround but I'd like to have something from php.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您需要
fnmatch()
?如果您需要更多信息,您应该发布一些示例数据。
Maybe you need
fnmatch()
?You should post some sample data if you need further info.
您可能会使用
fnmatch
,它是为您要求解决的任务而构建的。如果这不太合适,也许可以使用正则表达式。澄清您的面具的组成可能有助于指导您找到您想要的答案。
You could likely use
fnmatch
which is built for the task you are asking to solve. If that is not quite suitable, perhaps regular expressions could be of use.Clarifying what your mask consists of would likely help guide answers towards what you want.