删除与正则表达式匹配的文件 [英] Delete files that match regex

查看:193
本文介绍了删除与正则表达式匹配的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从目录中删除与Windows中Perl中的某些正则表达式匹配的所有文件的最简便的方法。

Shortest and nicest way to delete all files from directory that match certain regex in Perl on Windows.

我的示例:删除所有 *。 txt 目录中的文件,但保留 tmp.txt 吗? Windows。

My example: delete all *.txt files from directory, but leave tmp.txt? Windows.

推荐答案

# glob gets the names of all .txt files
# we apply grep to remove tmp.txt from the list
@files = grep (!/^tmp\.txt$/,glob('*.txt'));

# delete the files
unlink @files;

这篇关于删除与正则表达式匹配的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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