common/tools/listdir.pl
author Dario Sestito <darios@symbian.org>
Mon, 08 Mar 2010 14:18:19 +0000
changeset 907 bab81256b297
parent 108 d33d43677cdf
permissions -rw-r--r--
Remove Raptor log preprocessing as no longer needed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
     1
#!perl -w
108
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
     2
# Copyright (c) 2009 Symbian Foundation Ltd
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
     3
# This component and the accompanying materials are made available
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
     4
# under the terms of the License "Eclipse Public License v1.0"
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
     5
# which accompanies this distribution, and is available
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
     7
#
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
     8
# Initial Contributors:
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
     9
# Symbian Foundation Ltd - initial contribution.
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
    10
# 
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
    11
# Contributors:
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
    12
#
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
    13
# Description:
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
    14
# Recursive listing of a directory, outputting lower-cased relative paths with unix dir separators
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 78
diff changeset
    15
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    16
use strict;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    17
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    18
my $dir      = shift or die "Usage: $0 <dir> \n";   #  provided dir to traverse
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    19
my $filelist = [];
78
52cc4f7310db Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents: 39
diff changeset
    20
my $init = $dir = lc($dir);
52cc4f7310db Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents: 39
diff changeset
    21
$init =~ s{\\}{\\\\};
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    22
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    23
# fwd declaration to prevent warning
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    24
sub recursedir($$);
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    25
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    26
# run recurse and print
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    27
recursedir ($dir, $filelist);
78
52cc4f7310db Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents: 39
diff changeset
    28
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    29
print $_, "\n" for(@$filelist);
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    30
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    31
sub recursedir($$) {
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    32
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    33
  my $dir  = shift @_;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    34
  my $list = shift @_;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    35
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    36
  if(opendir(DIR, "$dir")) {
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    37
    #  list dir
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    38
    for my $file(grep { !/^\./ } readdir DIR) {
78
52cc4f7310db Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents: 39
diff changeset
    39
      if(-d "$dir/$file") {
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    40
        #  traverse subdirs
78
52cc4f7310db Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents: 39
diff changeset
    41
        recursedir("$dir/$file", $list);
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    42
      }
78
52cc4f7310db Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents: 39
diff changeset
    43
      elsif(-f "$dir/$file") {
52cc4f7310db Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents: 39
diff changeset
    44
        my $formatted = lc($dir)."/".lc($file);
52cc4f7310db Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents: 39
diff changeset
    45
        $formatted =~ s!$init/!!;
52cc4f7310db Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents: 39
diff changeset
    46
        push @$list, $formatted;
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    47
      }
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    48
    }
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    49
    closedir DIR;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    50
  }
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    51
  else {
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    52
    warn "Cannot open the directory '$dir' $!\n";
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    53
  }
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    54
}