Thomas
Thomas

Reputation: 649

Perl list files under multiple directories

I've currently got this to grab all files under Assets/Editor

@files = bsd_glob( "Assets/Editor/postprocessbuildplayer_*", GLOB_NOCASE );

But I would like to access all files starting with postprocessbuildplayer_ starting from Assets as my root folder.

Example:

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

The entire script should anyone know a better way:

#!/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, [email protected]

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;
        }
    }
}

Upvotes: 0

Views: 755

Answers (1)

Miller
Miller

Reputation: 35198

Use File::Find to recurse a directory tree

use strict;
use warnings;

use File::Find;

my @files;

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

Upvotes: 3

Related Questions