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:$!";
  }
}
相关推荐
charlie11451419114 分钟前
Cinux: 加载第一个内核:从 bootloader 跳进 C++
linux·开发语言·c++·嵌入式
. . . . .1 小时前
Egg框架深入
java·开发语言
C+-C资深大佬1 小时前
python while循环
服务器·开发语言·python
Tian_Hang1 小时前
eclipse ditto 学习笔记
运维·服务器·开发语言·javascript·3d
星夜夏空991 小时前
C++学习(2) —— 类与对象基础
开发语言·c++·学习
倒流时光三十年2 小时前
Java 内存模型(JMM)通俗解释
java·开发语言
码兄科技2 小时前
Java AI智能体开发实战:从零构建企业级智能应用指南
java·开发语言·人工智能
zh路西法2 小时前
【现代控制理论与卡尔曼滤波】从状态空间到Python仿真实现
开发语言·python
Evand J2 小时前
【论文复现】MATLAB例程,存在测距误差的WSN无锚点分布式自定位,《WSN中存在测距误差的无锚点分布式自定位方法》
开发语言·分布式·matlab·定位·导航·wsn
techdashen3 小时前
kTLS 进入 rustls 组织:把 TLS 的数据面交给内核
开发语言·php