while (defined($name = readdir $dh)) {
next unless -d "$root/$name";
$dir=$root.$name."/";
if(is_folder_empty($dir)){
print"$dir is Empty\n";
print"Do you want to delete it? 1-Yes 2-No\n";
$aa=<STDIN>;
chomp $aa;
if($aa==1){
$deleteregdir = "$dir";
rmdir $deleteregdir;
print"Directory has been deleted!!\n";
}
}
else
{
print"$dir is NOT Empty\n";
$dir2=$dir;
opendir my $dh2, $dir2;
while (defined($name2 = readdir $dh2)) {
next unless -d "$dir2/$name2";
$dd=$dir2.$name2."/";
#print"$dd\n";
if(is_folder_empty($dd)){
print"$dd is Empty\n";
print"Do you want to delete it? 1-Yes 2-No\n";
$aa=<STDIN>;
chomp $aa;
if($aa==1){
$deleteregdir = "$dir";
rmdir $deleteregdir;
print"Directory has been deleted!!\n";
}
}
else
{
print"$dd is NOT Empty\n";
}
}
}
}
此代码仅针对目录及其子目录运行。迭代在下一级停止。我想搜索所有空目录。我希望结构是这样的,当我运行代码时,在得到用户的确认后,所有为空的目录都将被删除。提前致谢。