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:$!";
  }
}
相关推荐
闲人编程5 分钟前
用Python识别图片中的文字(Tesseract OCR)
开发语言·python·ocr·识图·codecapsule
程序员卷卷狗8 分钟前
JVM 内存结构与 GC 调优全景图
java·开发语言·jvm
froginwe1112 分钟前
HTML 段落
开发语言
z203483152019 分钟前
我与C++的故事
开发语言·c++·c++40周年
wuwu_q1 小时前
用通俗易懂 + Android 开发实战的方式讲解 Kotlin Flow 中的 filter 操作符
android·开发语言·kotlin
想唱rap1 小时前
Linux开发工具(4)
linux·运维·服务器·开发语言·算法
Geoking.1 小时前
【Java】Java 中 @Resource 与 @Autowired 的区别详解
java·开发语言
生而为虫1 小时前
02.第一个Python程序
开发语言·python
星释2 小时前
Rust 练习册 :Rail Fence Cipher与栅栏密码
开发语言·算法·rust
weixin_441455262 小时前
说说Java有哪些集合类
java·开发语言