2014-03-28 47 views
0

我目前得到這個抓住所有文件下的資產/編輯下多個目錄的Perl列表文件

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

但我想訪問開始postprocessbuildplayer_從資產中起我的根文件夾中的所有文件。

例子:

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, [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; 
     } 
    } 
} 
+0

檢查HTTP://搜索。 cpan.org/~rjbs/perl-5.18.2/lib/File/Find.pm –

回答

3

使用File::Find遞歸目錄樹

use strict; 
use warnings; 

use File::Find; 

my @files; 

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

如何得到所有這些文件的清單放入@文件。我認爲說我真的不知道關於Perl的任何信息。 – Thomas

+0

已更新,將文件放入數組中而不是打印到屏幕上。 – Miller

相關問題