Chinaunix首页 | 论坛 | 博客
  • 博客访问: 150035
  • 博文数量: 22
  • 博客积分: 1476
  • 博客等级: 上尉
  • 技术积分: 470
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-15 17:07
文章分类

全部博文(22)

文章存档

2011年(4)

2010年(8)

2008年(10)

我的朋友
最近访客

分类: LINUX

2008-03-07 16:49:19

工作中可能需要收集某个目录下所有文件列表,下面是用PERL脚本实现的一个版本,算是抛砖引玉。
 
@rem = '--*-Perl-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
:WinNT
perl -x -S %0 %*
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
#!/usr/local/bin/perl -w
#line 15
use strict;
use File::Find;
my $path = ".";
find(\&process, $path);
sub process
{
        if($_ =~ /(\.cc$)|(\.hh$)/){
         my $dir = $File::Find::dir;
         $dir =~ s/^\.\///;
         $dir =~ s/\//\\/g;
         print $dir."";
        }
}
exit 0;
__END__
:endofperl
 
1 复制上述代码,存储到一个新批处理文件中,如rlist.bat
2 把rlist.bat拷备到需要列出所有文件的目录下
3 通过命令行窗口执行rlist.bat > flist.txt,文件列表就会存储到重定向文件flist.txt中
注:测试在perl V5.8.4下OK
阅读(1053) | 评论(0) | 转发(0) |
0

上一篇:rose2003教程

下一篇:母亲

给主人留下些什么吧!~~