perl批量改文件后缀

perl批量改文件后缀

如题,perl批量改文件后缀,将已有的统一格式的文件后缀,修改为新的统一的文件后缀。

perl 复制代码
#!/bin/perl
use 5.010;

print "Please input file suffix which U want to rename!\n";
chomp (my $suffix_old = <>); # 去除输入中的回车符
print "Please output file suffix which U want to rename!\n";
chomp (my $suffix_new = <>);

foreach my $file(glob "*.$suffix_old") {
  my $new_file = $file;
  $new_file =~ s/\.$suffix_old/.$suffix_new/gm;
  if (-e $new_file) {
    warn "Cannot rename $file to $new_file: $new_file exists\n";
  } elsif (rename $file => $new_file) {
  } else {
    warn "rename $file to $new_file failed:$!";
  }
}
相关推荐
学渣676565 分钟前
什么时候使用Python 虚拟环境(venv)而不用conda
开发语言·python·conda
想睡hhh16 分钟前
c++STL——stack、queue、priority_queue的模拟实现
开发语言·c++·stl
小鹿鹿啊25 分钟前
C语言编程--14.电话号码的字母组合
c语言·开发语言·算法
Sunlight_77727 分钟前
第六章 QT基础:6、QT的Qt 时钟编程
开发语言·qt·命令模式
cloues break.27 分钟前
C++初阶----模板初阶
java·开发语言·c++
wwww.wwww1 小时前
Qt软件开发-摄像头检测使用软件V1.1
开发语言·c++·qt
sugar__salt1 小时前
多线程(1)——认识线程
java·开发语言
Evand J2 小时前
MATLAB技巧——平滑滤波,给出一定的例程和输出参考
开发语言·matlab
LCY1332 小时前
python 与Redis操作整理
开发语言·redis·python