author | dario |
Tue, 05 May 2009 15:27:03 +0100 | |
changeset 179 | 7b5eef3a9124 |
parent 39 | 9edae8fe1416 |
child 78 | 52cc4f7310db |
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 = []; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
6 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
7 |
# 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
|
8 |
sub recursedir($$); |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
9 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
10 |
# 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
|
11 |
recursedir ($dir, $filelist); |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
12 |
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
|
13 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
14 |
sub recursedir($$) { |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
15 |
|
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
16 |
my $dir = shift @_; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
17 |
my $list = shift @_; |
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 |
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
|
20 |
# list dir |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
21 |
for my $file(grep { !/^\./ } readdir DIR) { |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
22 |
if(-d "$dir\\$file") { |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
23 |
# traverse subdirs |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
24 |
recursedir("$dir\\$file", $list); |
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 |
elsif(-f "$dir\\$file") { |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
27 |
# if file then swap (any present) fwd to bkslash and add to list |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
28 |
$dir =~s/\//\\/; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
29 |
$file =~s/\//\\/; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
30 |
push @$list, "$dir\\$file"; |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
31 |
} |
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 |
closedir DIR; |
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 |
else { |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
36 |
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
|
37 |
} |
9edae8fe1416
Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff
changeset
|
38 |
} |