|
1 #!/usr/bin/perl |
|
2 |
|
3 # Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 # All rights reserved. |
|
5 # This component and the accompanying materials are made available |
|
6 # under the terms of "Eclipse Public License v1.0" |
|
7 # which accompanies this distribution, and is available |
|
8 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 # |
|
10 # Initial Contributors: |
|
11 # Nokia Corporation - initial contribution. |
|
12 # |
|
13 # Contributors: |
|
14 # |
|
15 # Description: |
|
16 # setold.pl - sets the last modified date of all files under a path to 1970 |
|
17 # |
|
18 # |
|
19 |
|
20 $date = 500000000; # e.g 0 = 00:00 1st Jan 1970, 1000000000 (10^9) = 01:46 9th Sep 2001 |
|
21 |
|
22 my ($path, $batch) = readOpts(@ARGV); |
|
23 |
|
24 if (!$batch) |
|
25 { |
|
26 print "Setting all files under path '$path' to be last modified at ".localtime($date).".\nAre you sure (Y/N)?\n"; |
|
27 |
|
28 if (lc(getc(STDIN)) ne "y") |
|
29 { |
|
30 print "Aborting.\n"; |
|
31 exit 0; |
|
32 } |
|
33 } |
|
34 |
|
35 setOld($path,$date); |
|
36 |
|
37 exit 0; |
|
38 |
|
39 sub readOpts(@) |
|
40 { |
|
41 my (@args) = @_; |
|
42 |
|
43 my $path = undef; |
|
44 my $batch = 0; |
|
45 |
|
46 foreach my $arg (@args) |
|
47 { |
|
48 if ($arg =~ /^-/) |
|
49 { |
|
50 if ((lc($arg) eq "--help") |
|
51 ||(lc($arg) eq "-h") |
|
52 ) |
|
53 { |
|
54 showHelp(); |
|
55 exit 0; |
|
56 } |
|
57 elsif (lc($arg) eq "--batch") |
|
58 { |
|
59 $batch = 1; |
|
60 } |
|
61 else |
|
62 { |
|
63 print STDERR "Option '$arg' not recognised.\n\n"; |
|
64 print STDERR "Try 'setold.pl --help' for help.\n"; |
|
65 exit 1; |
|
66 } |
|
67 } |
|
68 else |
|
69 { |
|
70 if (defined($path)) |
|
71 { |
|
72 print STDERR "Setold accepts only one argument.\n\n"; |
|
73 print STDERR "Try 'setold.pl --help' for help.\n"; |
|
74 exit 1; |
|
75 } |
|
76 else |
|
77 { |
|
78 $path = $arg; |
|
79 } |
|
80 } |
|
81 } |
|
82 |
|
83 if (!defined($path)) |
|
84 { |
|
85 print STDERR "Setold must be given a path to set.\n\n"; |
|
86 print STDERR "Try 'setold.pl --help' for help.\n"; |
|
87 exit 1; |
|
88 } |
|
89 |
|
90 return ($path, $batch); |
|
91 } |
|
92 |
|
93 sub setOld($$) |
|
94 { |
|
95 my ($path,$date) = @_; |
|
96 |
|
97 opendir(PATH, $path); |
|
98 my @dir = readdir(PATH); |
|
99 closedir(PATH); |
|
100 |
|
101 foreach $entry (@dir) |
|
102 { |
|
103 if ($entry =~ /^\.\.?$/) |
|
104 { |
|
105 } |
|
106 elsif (-d $path."\\".$entry) |
|
107 { |
|
108 setOld($path."\\".$entry,$date); |
|
109 } |
|
110 else |
|
111 { |
|
112 # Set file's last modified stamp |
|
113 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($path."\\".$entry); |
|
114 |
|
115 utime $atime, $date, ($path."\\".$entry) or print "Failed to set $path\\$entry\n"; |
|
116 } |
|
117 } |
|
118 } |
|
119 |
|
120 sub showHelp() |
|
121 { |
|
122 my ($date) = @_; |
|
123 |
|
124 print "setold.pl [options] Path\n"; |
|
125 print " - sets the last modified date of all files under a path to ".localtime($date)."\n\n"; |
|
126 print " Path - The path to the root of the files to be modified\n"; |
|
127 print "Options:\n"; |
|
128 print " --batch - Don't prompt for confirmation (use with care)\n"; |
|
129 print " --help or -h - Display this message\n\n"; |
|
130 print "Note that this tool always operates on all subdirectories of the given path\n"; |
|
131 } |
|
132 |