|
1 # Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # |
|
15 |
|
16 package FileOps; |
|
17 use strict; |
|
18 use Carp; |
|
19 use File::Copy; |
|
20 use File::Path; |
|
21 use Cwd; |
|
22 |
|
23 sub ProcessDir |
|
24 { |
|
25 my ($iSourceDir, $iTargetDir, $iAction, @iExcludes) = @_; |
|
26 my ($iFile); |
|
27 |
|
28 opendir(DIR, $iSourceDir) or croak "can't opendir $iSourceDir: $!"; |
|
29 DIR: while (defined($iFile = readdir(DIR))) |
|
30 { |
|
31 next DIR if $iFile =~ /^\.\.?$/; # skip . and .. |
|
32 foreach my $iExclude (@iExcludes) |
|
33 { |
|
34 if ($iExclude =~ /^$iFile$/) |
|
35 { |
|
36 print "Excluding $iExclude\n"; |
|
37 next DIR; |
|
38 } |
|
39 } |
|
40 if ( lc($iAction) eq 'copy') |
|
41 { |
|
42 print "Copying $iSourceDir\\$iFile to $iTargetDir\\$iFile\n"; |
|
43 if (-d "$iSourceDir\\$iFile") |
|
44 { |
|
45 system ("xcopy $iSourceDir\\$iFile", "$iTargetDir\\$iFile", "/E", "/Z", "/I"); |
|
46 } else { |
|
47 system ("xcopy $iSourceDir\\$iFile", "$iTargetDir", "/Z"); |
|
48 } |
|
49 } elsif ( lc($iAction) eq 'move') { |
|
50 print "Moving $iSourceDir\\$iFile to $iTargetDir\\$iFile\n"; |
|
51 &move("$iSourceDir\\$iFile", "$iTargetDir\\$iFile"); |
|
52 } elsif ( lc($iAction) eq 'delete') { |
|
53 print "Deleting $iSourceDir\\$iFile\n"; |
|
54 if (-d "$iSourceDir\\$iFile") |
|
55 { |
|
56 rmtree("$iSourceDir\\$iFile"); |
|
57 } else { |
|
58 unlink("$iSourceDir\\$iFile"); |
|
59 } |
|
60 } elsif ( lc($iAction) eq 'zip') { |
|
61 if (-d "$iSourceDir\\$iFile") |
|
62 { |
|
63 print "Ziping $iSourceDir\\$iFile\n"; |
|
64 chdir("$iSourceDir"); |
|
65 system("zip -r $iTargetDir\\$iFile.zip $iFile"); |
|
66 } |
|
67 } |
|
68 } |
|
69 closedir(DIR); |
|
70 } |
|
71 |
|
72 1; |