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:$!";
  }
}
相关推荐
m0_662577971 分钟前
模板编译期哈希计算
开发语言·c++·算法
m0_662577971 分钟前
C++代码静态检测
开发语言·c++·算法
阿贵---2 分钟前
编译器命令选项优化
开发语言·c++·算法
add45a2 分钟前
分布式计算C++库
开发语言·c++·算法
「QT(C++)开发工程师」4 分钟前
C++并发编程新纪元:线程库、异步操作与泛型Lambda深度解析
开发语言·c++
-许平安-7 分钟前
MCP项目笔记四(Transport)
开发语言·c++·笔记·ai·mcp
Felven7 分钟前
C. Stable Groups
c语言·开发语言
SuperEugene8 分钟前
Vue3 + Element Plus 表单校验实战:规则复用、自定义校验、提示语统一,告别混乱避坑|表单与表格规范篇
开发语言·前端·javascript·vue.js·前端框架
2401_894241928 分钟前
基于C++的数据库连接池
开发语言·c++·算法
阿贵---9 分钟前
C++中的适配器模式
开发语言·c++·算法