#!/usr/bin/perl
use strict;
use warnings;
my $dir = '/path/to/directory'; # 替换成实际目录路径
my $dest_dir = '/path/to/destination'; # 替换成实际目标目录路径
opendir(DIR, $dir) or die "Could not open directory: $!\n";
while (my $sub_dir = readdir(DIR)) {
next if ($sub_dir =~ /^\.{1,2}$/); # 跳过当前目录和上级目录
next unless (-d "$dir/$sub_dir"); # 只处理子目录,跳过文件
opendir(SUB_DIR, "$dir/$sub_dir") or die "Could not open subdir: $!\n";
while (my $file = readdir(SUB_DIR)) { # 遍历子目录中的文件
next if ($file =~ /^\.{1,2}$/); # 跳过当前目录和上级目录
rename("$dir/$sub_dir/$file", "$dest_dir/$file") or die "Could not move file: $!\n"; # 将文件移动到目标目录中
}
closedir(SUB_DIR);
}
closedir(DIR);
将/path/to/directory
替换成实际目录路径,将/path/to/destination
替换为实际目标目录路径,然后保存为脚本文件(例如move_files.pl
)并在终端中执行此脚本即可。