使用perl删除不同的文件,该名称以diefferent名称扩展而结束,例如动态日期和小时

发布于 2025-02-10 00:18:00 字数 552 浏览 4 评论 0原文

我想删除目录中的许多文件。问题是扩展不相同。结尾是动态的: .DAT_20220526_061224

.DAT_20220525_041226

.DAT_20220514_081212

此扩展名是动态的,但是有相同的模型

,请有人可以帮助我 谢谢!

这是我的代码

use strict;
use warnings;

my $dir = "D:/perl-projet/";

if ( -e $dir)
{
    
    unlink $dir . "log.dat_20220518_233007"; #this ligne is work quand i put all name of the file ( the was been deleted)
    
    #unlink(glob("${$dir}log.dat_???));      #this ligne didn"t work
    
    
    #unlink glob "$dir/*.dat_";           # this ligne didn"t too
}

I want to delete many file in my directory the problem is that the extension of that is not the same. the end is dynamic like:
.dat_20220526_061224

.dat_20220525_041226

.dat_20220514_081212

this extension is dynamic is change but there have same model

please somebody could help me
thanks!

this is my code

use strict;
use warnings;

my $dir = "D:/perl-projet/";

if ( -e $dir)
{
    
    unlink $dir . "log.dat_20220518_233007"; #this ligne is work quand i put all name of the file ( the was been deleted)
    
    #unlink(glob("${$dir}log.dat_???));      #this ligne didn"t work
    
    
    #unlink glob "$dir/*.dat_";           # this ligne didn"t too
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月松间行 2025-02-17 00:18:00
glob("*.dat_*");

glob("*.dat_????????_??????");

grep /\.dat_\d{8}_\d{6}\z/, glob("*");;
glob("*.dat_*");

or

glob("*.dat_????????_??????");

or

grep /\.dat_\d{8}_\d{6}\z/, glob("*");;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文