删除具有相同前缀的文件 [英] Delete files which has the same prefix

查看:151
本文介绍了删除具有相同前缀的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$prefix = 'something_prefix';
unlink($prefix.'.*');

上面的代码不起作用,但是我看到下面的一些代码可以正常工作

the code above is not working, but I see some code like this below works just fine

unlink('*.jpg');

为什么?我不知道这行得通吗?

why? I am wonder is this going to work?

unlink('*.*');

如何删除以相同字符串开头的文件?像这样

how to delete the files which they begin with the same string? like this

same123.jpg
sametoo.png
samexxx.gif

它们都以字符串"same"开头,但以不同的扩展名结尾,该怎么做?

they all begins with the string "same" but ends with different extension, how to do this?

我已经有一种便宜的方法可以做到这一点,但是我想知道是否有更好的解决方案?

I alread have a cheap way to do this, but I wonder if there is any better solution?

推荐答案

尝试以下代码:

$mask = 'your_prefix_*.*';
array_map('unlink', glob($mask));

p.s. glob()需要PHP 4.3.0 +

p.s. glob() requires PHP 4.3.0+

这篇关于删除具有相同前缀的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆