三种遍历文件夹方法比较(PERL)
一般黑客都常用遍历方法来进行插入挂马代码等。
三种遍历文件夹方法比较
本贴对三种遍历文件夹方法比较。
1. 使用File::Find;
2. 递归遍历。(遍历函数为lsr)
3. 使用队列或栈遍历。(遍历函数为lsr_s)
1.use File::Find
2. lsr递归遍历
#!/usr/bin/perl -W # # File: lsr.pl # Author: 路小佳 # License: GPL-2 use strict; use warnings; sub lsr($) { sub lsr; my $cwd = shift; local *DH; if (!opendir(DH, $cwd)) { warn "Cannot opendir $cwd: $! $^E"; return undef; } foreach (readdir(DH)) { if ($_ eq '.' || $_ eq '..') { next; } my $file = $cwd.'/'.$_; if (!-l $file && -d _) { $file .= '/'; lsr($file); } process($file, $cwd); } closedir(DH); } my ($size, $dircnt, $filecnt) = (0, 0, 0); sub process($$) { my $file = shift; #print $file, "\n"; if (substr($file, length($file)-1, 1) eq '/') { $dircnt++; } else { $filecnt++; $size += -s $file; } } lsr('.'); print "$filecnt files, $dircnt directory. $size bytes.\n";
[1] [2] 下一页
| 设为首页 | 加入收藏 | 友情链接 | 法律顾问 | 关于我们 | 版权申明 | 付款方式 | 广告服务 | 网站地图 | 联系我们 |
Copyright @ 2005 77169.Net Inc. All rights reserved. 华夏黑客同盟 版权所有 北京市电信通提供网络带宽