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:$!";
  }
}
相关推荐
落叶-IT6 小时前
Java Scanner 类精讲:控制台交互
java·开发语言
chh5636 小时前
C++--string
java·开发语言·网络·c++·学习
梦想的旅途26 小时前
企业微信外部群智能自动回复:基于RPA接口的关键词匹配方案
java·开发语言·数据库·机器人·自动化·企业微信
逝水无殇6 小时前
C# 多态性详解
开发语言·后端·c#
逝水无殇6 小时前
C# 继承(Inheritance)详解
开发语言·后端·c#
多加点辣也没关系6 小时前
JavaScript|第6章:流程控制语句
开发语言·前端·javascript
foundbug9997 小时前
Polar Code 编解码 MATLAB 实现
开发语言·算法·matlab
李小小钦7 小时前
D. Storming Arasaka(Codeforces 2238)
c语言·开发语言·数据结构·c++·算法
W是笔名7 小时前
python___容器类型的数据___列表
开发语言·windows·python
跨境数据猎手7 小时前
多平台电商比价系统从零搭建合规
开发语言·爬虫·架构