Termux脚本工具 批量修改视频文件扩展名

There's more than one way to do it!
https://metacpan.org http://perlmonks.org
回复
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

Termux脚本工具 批量修改视频文件扩展名

帖子 523066680 »

作用,批量给当前目录下(包括子目录)的视频文件扩展名加下划线,避免相册中出现这些"蜜汁"视频的预览图 :confidence

toggle.pl
调用:
perl toggle.pl

代码: 全选

use utf8;
use Encode;
use Modern::Perl;
use File::Find;
STDOUT->autoflush(1);

my @original;
my @changed;

my $exts = qr/(mp4|avi|ts|rmvb|wmv|mkv)/i;
find( { wanted => closure->( $exts, \@original, \@changed ) },  "./" );

# 只要有一个未处理格式的文件,先做格式伪装处理
if ( $#original >= 0 )
{
    say "Append underline to the file extension";
    for my $f ( @original )
    {
        rename $f, $f."_";
        say $f ."_";
    }
}
else
{
    # 切换回原来的格式
    say "Remove underline for the file extension";
    for my $f ( @changed )
    {
        my $newname = $f;
        $newname =~ s/_$//;
        rename $f, $newname;
        say $newname;
    }
}

sub closure
{
    my ( $filter, $orig, $changed ) = @_;
    return
        sub {
            if ( $File::Find::name =~ /${filter}$/ )
            {
                push @$orig, $File::Find::name;            
} elsif ( $File::Find::name =~ /${filter}_$/ ) { push @$changed, $File::Find::name;
} } } sub gbk { encode('gbk', $_[0]) } sub utf8 { encode('utf8', $_[0]) } sub u2gbk { encode('gbk', decode('utf8', $_[0])) } sub uni { decode('utf8', $_[0]) }
头像
rubyish
渐入佳境
渐入佳境
帖子: 52
注册时间: 2018年04月23日 09:58
联系:

Re: Termux脚本工具 批量修改视频文件扩展名

帖子 rubyish »

:shy 3Q~

$_
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 3 访客