xmove.pl

本文介绍了一个使用Perl脚本批量将子文件夹中的图片移动到主文件夹的方法。通过简单的交互确认,避免了手动频繁切换目录查看图片的麻烦。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

t0nsha用手机拍了很多照片:-)都保存在一个叫Images的文件夹下,照片根据拍摄日期分别存放在不同的子文件夹中,由于时间很久了,图片也就零零散散的散布在各个角落里,于是看起来就麻烦了,看两张就得切换好几次目录!-_- t0nsha没这个耐心,想想要是能把Images文件夹下所有子文件夹里的图片都移到Images文件夹,看起来不就方便多了吗?恰好上星期被抓去学Perl,何不自己动手丰衣足食,还能练练手呢……

#!/usr/bin/perl #xmove.pl, created by t0nsha@20090709, version: 0.01; #used for move all files in one directory to another. use warnings; use File::Find qw(find); use File::Copy qw(move); use File::Spec::Functions qw(catfile rel2abs); use Cwd qw(getcwd); sub move_file { if ( -f $_ ) { $dst_fil = catfile( $dst_dir, $_ ); if ( $override_all == 0 and $skip_all == 0 ) { if ( -e $dst_fil ) { while (1) { print "File $dst_fil has already existed! Override This(o)/Override All(oa)/Skip This(s)/Skip All(sa)/Exit(e):"; chomp( $ose = lc(<STDIN>) ); if ( $ose eq "o" ) { $move_this = 1; last; } elsif ( $ose eq "oa" ) { $override_all = 1; last; } elsif ( $ose eq "s" ) { $move_this = 0; last; } elsif ( $ose eq "sa" ) { $skip_all = 1; last; } elsif ( $ose eq "e" ) { exit 0; } else { next; } } } } $src_fil = rel2abs($_); if ( ( -e $dst_fil ) and ( $move_this == 0 or $skip_all == 1 ) ) { print "$src_fil ignored!/n"; } else { print "$src_fil" . " --> " . "$dst_fil/n"; move( $_, $dst_fil ); $moved_cnt++; } $total_cnt++; } } $move_this = 0; $override_all = 0; $skip_all = 0; $moved_cnt = 0; $total_cnt = 0; $src_dir = rel2abs( $ARGV[0] || getcwd ); $dst_dir = rel2abs( $ARGV[1] || getcwd ); print "Move all files in $src_dir to $dst_dir (y/n)?"; chomp( $yn = <STDIN> ); exit 0 if ( lc($yn) ne "y" ); find( /&move_file, $src_dir ); print "Total $total_cnt files found inside $src_dir, $moved_cnt moved to $dst_dir.";

哈哈,现在t0nsha终于可以好好地回味一番了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值