Perl列出多个目录下的文件

时间:2014-03-28 09:21:05

标签: perl

我目前正在使用它来获取Assets / Editor

下的所有文件
@files = bsd_glob( "Assets/Editor/postprocessbuildplayer_*", GLOB_NOCASE );

但是我想访问以posttsbuildplayer_开头的所有文件,从Assets开始作为我的根文件夹。

示例:

Assets/Temp/Editor/PostprocessBuildPlayer_DWARF
Assets/Directory_1/Editor/PostprocessBuildPlayer_1
Assets/Editor/PostprocessBuildPlayer_Default

整个剧本应该让任何人都知道更好的方法:

#!/usr/bin/perl


# Post Process Build Player -- Master 
# Searches for other PostprocessBuildPlayer scripts and executes them. Make sure the other script
# have a name suffix with an underscore "_" like "PostprocessBuildPlayer_AnotherBuild" or whatever.
#
# Based on script by Rob Terrell, rob@stinkbot.com

use File::Glob ':glob';

# Grab all the PostprocessBuildPlayer files
@files = bsd_glob( "Assets/Editor/postprocessbuildplayer_*", GLOB_NOCASE );

foreach $file( @files )
{
    if( !( $file =~ m/\./ ) )
    {
        system( "chmod", "755", $file );
        print "PostProcessBuildPlayer: calling " . $file . "\n";
        system( $file, $ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5], $ARGV[6] );

        if ( $? == -1 )
        {
          print "command failed: $!\n";
        }
        else
        {
          printf "command exited with value %d", $? >> 8;
        }
    }
}

1 个答案:

答案 0 :(得分:3)

使用File::Find递归目录树

use strict;
use warnings;

use File::Find;

my @files;

find(sub {
    push @files, File::Find::name if /^PostprocessBuildPlayer/;
}, 'Assets/');