common/tools/listdir.pl
author Simon Howkins <simonh@symbian.org>
Tue, 05 May 2009 14:21:55 +0100
changeset 84 fcf94a72b33e
parent 78 52cc4f7310db
child 108 d33d43677cdf
permissions -rw-r--r--
Improved zip template generation script, to take a third argument for the required location of the output file. Updated build script to supply third argument. Standardised indentation in build.xml - 4 columns; no tabs.

#!perl -w
use strict;

my $dir      = shift or die "Usage: $0 <dir> \n";   #  provided dir to traverse
my $filelist = [];
my $init = $dir = lc($dir);
$init =~ s{\\}{\\\\};

# fwd declaration to prevent warning
sub recursedir($$);

# run recurse and print
recursedir ($dir, $filelist);

print $_, "\n" for(@$filelist);

sub recursedir($$) {

  my $dir  = shift @_;
  my $list = shift @_;

  if(opendir(DIR, "$dir")) {
    #  list dir
    for my $file(grep { !/^\./ } readdir DIR) {
      if(-d "$dir/$file") {
        #  traverse subdirs
        recursedir("$dir/$file", $list);
      }
      elsif(-f "$dir/$file") {
        my $formatted = lc($dir)."/".lc($file);
        $formatted =~ s!$init/!!;
        push @$list, $formatted;
      }
    }
    closedir DIR;
  }
  else {
    warn "Cannot open the directory '$dir' $!\n";
  }
}