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:$!";
  }
}
相关推荐
yong9990几秒前
基于MATLAB的激光器锁模技术仿真
开发语言·matlab
小肖爱笑不爱笑2 分钟前
登录认证-会话技术、JWT令牌、过滤器Filter、拦截器Interceptor
java·开发语言·过滤器·拦截器·登录认证
柳鲲鹏1 小时前
地图影像匹配:基于特征匹配的视觉定位2,python
开发语言·python
郝学胜-神的一滴2 小时前
深入理解网络IP协议与TTL机制:从原理到实践
linux·服务器·开发语言·网络·网络协议·tcp/ip·程序人生
程序猿_极客5 小时前
【2025 年最新版】Java JDK 安装与环境配置教程(附图文超详细,Windows+macOS 通用)
java·开发语言·windows·macos·jdk
二哈喇子!8 小时前
BOM模型
开发语言·前端·javascript·bom
二哈喇子!8 小时前
空指针异常
开发语言
咚为8 小时前
Rust Print 终极指南:从底层原理到全场景实战
开发语言·后端·rust
%xiao Q9 小时前
GESP C++五级-202406
android·开发语言·c++
Psycho_MrZhang9 小时前
Neo4j Python SDK手册
开发语言·python·neo4j