perl - 使用perl重命名txt文件扩展名

标签 perl

我正在执行以下步骤:

读取目录中的所有文本文件并将其存储在名为@files的数组中 对每个文本文件运行 foreach 循环。使用拆分操作提取文件名(剥离 .txt)并创建该特定文件名的文件夹。将该文件重命名为 Test.txt(以便作为另一个 perl 可执行文件的输入) 通过添加行 require "test.pl"; 为每个文件执行 test.pl; 它仅适用于一个文件,但不再适用。这是我的代码:

opendir DIR, ".";
my @files = grep {/\.txt/} readdir DIR;

foreach my $files (@files) {

    @fn = split '\.', $files;
    mkdir "$fn[0]" 
        or die "Unable to create $fn[0] directory <$!>\n";

    rename "$files", "Test.txt";
    require "test3.pl";

    rename "Test.txt", "$files";
    system "move $files $fn[0]";
}

最佳答案

您不要求文件加载一次,但是do每次都没有。

所以,替换

需要“test3.pl”;

执行“test3.pl”;

关于perl - 使用perl重命名txt文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16791464/

相关文章:

perl - 为什么带有 uwsgi_psgi 的 Perlbrew PSGI 应用程序会导致 "wrong"Perl 包含路径?

perl - LDAP Active Directory 身份验证问题

sql - 无法从 csv 文件中选择列

perl - 如何追踪 Devel::Peek 的起源

perl - 在 Perl 中关闭 'use Module' 语句中生成的警告的任何方法

regex - 将字符串截断至 PCRE 中的大小

sql - 如何在 SQL 准备语句中转义单引号和双引号?

perl - 使用 Perl 通过 G Suite 发送电子邮件

perl rand lc/uc

perl - 快速打印美元负值的方法