author | Shabe Razvi <shaber@symbian.org> |
Tue, 26 May 2009 17:00:51 +0100 | |
changeset 109 | cb16ca6483d9 |
parent 78 | 52cc4f7310db |
child 108 | d33d43677cdf |
permissions | -rw-r--r-- |
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 |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
2 |
use strict; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
3 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
4 |
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
|
5 |
my $filelist = []; |
78
52cc4f7310db
Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents:
39
diff
changeset
|
6 |
my $init = $dir = lc($dir); |
52cc4f7310db
Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents:
39
diff
changeset
|
7 |
$init =~ s{\\}{\\\\}; |
39
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
8 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
9 |
# 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
|
10 |
sub recursedir($$); |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
11 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
12 |
# 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
|
13 |
recursedir ($dir, $filelist); |
78
52cc4f7310db
Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents:
39
diff
changeset
|
14 |
|
39
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
15 |
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
|
16 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
17 |
sub recursedir($$) { |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
18 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
19 |
my $dir = shift @_; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
20 |
my $list = shift @_; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
21 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
22 |
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
|
23 |
# list dir |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
24 |
for my $file(grep { !/^\./ } readdir DIR) { |
78
52cc4f7310db
Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents:
39
diff
changeset
|
25 |
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
|
26 |
# traverse subdirs |
78
52cc4f7310db
Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents:
39
diff
changeset
|
27 |
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
|
28 |
} |
78
52cc4f7310db
Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents:
39
diff
changeset
|
29 |
elsif(-f "$dir/$file") { |
52cc4f7310db
Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents:
39
diff
changeset
|
30 |
my $formatted = lc($dir)."/".lc($file); |
52cc4f7310db
Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents:
39
diff
changeset
|
31 |
$formatted =~ s!$init/!!; |
52cc4f7310db
Strip drive and dir root from listing
Shabe Razvi <shaber@symbian.org>
parents:
39
diff
changeset
|
32 |
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
|
33 |
} |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
34 |
} |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
35 |
closedir DIR; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
36 |
} |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
37 |
else { |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
38 |
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
|
39 |
} |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
40 |
} |