-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchext.pl
More file actions
39 lines (25 loc) · 819 Bytes
/
chext.pl
File metadata and controls
39 lines (25 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/opt/perl5/bin/perl
# $Id: chext.pl,v 1.1 2003/11/11 22:02:22 swain Exp $
# change the extensions of all matching files in current working directory
die "Usage: $0 .oldext .newext\n" unless ($ARGV[0] and $ARGV[1]);
die "Usage: $0 .oldext .newext (use the dots!)\n"
unless ( ($ARGV[0] =~ /^\./) and ($ARGV[1] =~ /^\./) );
chdir $ENV{PWD};
#print "now in: " , `pwd`;
$oldext = $ARGV[0];
$newext = $ARGV[1];
print "Change $oldext to $newext? [Y/n]\n";
$answer = <STDIN>;
chomp $answer;
#print "answer: '$answer'\n";
exit unless ($answer eq 'Y' or $answer eq 'y' or $answer eq '');
print "Renaming files...\n";
@files = <*$oldext>;
foreach $file (@files) {
# print "got: '$file'\n";
$file =~ m/$oldext$/;
$base = $`;
my $cmd = "cp $file $base$newext";
print $cmd, "\n";
`$cmd`;
}