如何使用正则表达式而不是 glob 表达式来过滤文件名?
我正在过滤目录中的文件:
chdir '/home/brian/mypics/';
@picArray = <*.JPG *.GIF *.jpg *.gif *.PNG *.png *.jpeg>;
@soundArray = <*.mid *.MID *.wav *.WAV *.mp3 *.MP3 *.wma *.WMA *.ogg *.OGG>;
我知道必须有一种更好、更简单的方法,这种方法不区分大小写,并且可以允许像 gif|png|jpe?g
和 wma 这样的正则表达式|ogg|mp3|wave?|midi?
。
我怎样才能有一个数组来捕获所有未知的文件类型(例如,如果一个是.exe
,那么它将在一个数组中,而其他两个文件从未捕获它)?
I am filtering files of a directory:
chdir '/home/brian/mypics/';
@picArray = <*.JPG *.GIF *.jpg *.gif *.PNG *.png *.jpeg>;
@soundArray = <*.mid *.MID *.wav *.WAV *.mp3 *.MP3 *.wma *.WMA *.ogg *.OGG>;
I know there has to be a better and easier way, something that's case-insensitive and can allow for regex like gif|png|jpe?g
and wma|ogg|mp3|wave?|midi?
.
How can I have an array to catch all unknown file types (such if one was .exe
, it would be in an array all of it's own as the other two never caught it)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
opendir/readdir 可以工作:
opendir/readdir would work: