Advertisement
Guest User

Untitled

a guest
Dec 7th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.50 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
  4.     if 0; # not running under some shell
  5. # $Revision$$Date$
  6. # Robin's RCS header:
  7. # RCSfile: rename.PL,v Revision: 1.3   Date: 2006/05/25 09:20:32
  8. # Larry's RCS header:
  9. #  RCSfile: rename,v   Revision: 4.1   Date: 92/08/07 17:20:30
  10. #
  11. #  Log: rename,v
  12. # Revision 1.5  1998/12/18 16:16:31  rmb1
  13. # moved to perl/source
  14. # changed man documentation to POD
  15. #
  16. # Revision 1.4  1997/02/27  17:19:26  rmb1
  17. # corrected usage string
  18. #
  19. # Revision 1.3  1997/02/27  16:39:07  rmb1
  20. # added -v
  21. #
  22. # Revision 1.2  1997/02/27  16:15:40  rmb1
  23. # *** empty log message ***
  24. #
  25. # Revision 1.1  1997/02/27  15:48:51  rmb1
  26. # Initial revision
  27. #
  28.  
  29. use strict;
  30. require File::Rename;
  31. require File::Rename::Options;
  32. use Pod::Usage;
  33.  
  34. main() unless caller;
  35.  
  36. sub main {
  37.     my $options = File::Rename::Options::GetOptions()
  38.         or pod2usage;
  39.  
  40.     mod_version() if $options->{show_version};
  41.     pod2usage( -verbose => 2 ) if $options->{show_manual};
  42.     pod2usage( -exitval => 1 ) if $options->{show_help};
  43.  
  44.     @ARGV = map {glob} @ARGV if $^O =~ m{Win}msx;
  45.  
  46.     File::Rename::rename(\@ARGV, $options);
  47. }
  48.  
  49. sub mod_version {
  50.     print __FILE__;
  51.     print ' using File::Rename version '.  $File::Rename::VERSION;
  52.     print ', File::Rename::Options version '. $File::Rename::Options::VERSION
  53.         if (eval $File::Rename::Options::VERSION) < (eval $File::Rename::VERSION);
  54.     print "\n\n";
  55.     exit 0
  56. }  
  57.  
  58. 1;
  59.  
  60. __END__
  61.  
  62. =head1 NAME
  63.  
  64. rename - renames multiple files
  65.  
  66. =head1 SYNOPSIS
  67.  
  68. B<rename>
  69. S<[ B<-h>|B<-m>|B<-V> ]>
  70. S<[ B<-v> ]>
  71. S<[ B<-0> ]>
  72. S<[ B<-n> ]>
  73. S<[ B<-f> ]>
  74. S<[ B<-e>|B<-E> I<perlexpr>]*|I<perlexpr>>
  75. S<[ I<files> ]>
  76.  
  77. =head1 DESCRIPTION
  78.  
  79. C<rename>
  80. renames the filenames supplied according to the rule specified as the
  81. first argument.
  82. The I<perlexpr>
  83. argument is a Perl expression which is expected to modify the C<$_>
  84. string in Perl for at least some of the filenames specified.
  85. If a given filename is not modified by the expression, it will not be
  86. renamed.
  87. If no filenames are given on the command line, filenames will be read
  88. via standard input.
  89.  
  90. For example, to rename all files matching C<*.bak> to strip the extension,
  91. you might say
  92.  
  93.     rename 's/\.bak$//' *.bak
  94.  
  95. To translate uppercase names to lower, you'd use
  96.  
  97.     rename 'y/A-Z/a-z/' *
  98.  
  99. =head1 OPTIONS
  100.  
  101. =over 8
  102.  
  103. =item B<-v>, B<-verbose>
  104.  
  105. Verbose: print names of files successfully renamed.
  106.  
  107. =item B<-0>, B<-null>
  108.  
  109. Use \0 as record separator when reading from STDIN.
  110.  
  111. =item B<-n>, B<-nono>
  112.  
  113. No action: print names of files to be renamed, but don't rename.
  114.  
  115. =item B<-f>, B<-force>
  116.  
  117. Over write: allow existing files to be over-written.
  118.  
  119. =item B<-h>, B<-help>
  120.  
  121. Help: print SYNOPSIS and OPTIONS.
  122.  
  123. =item B<-m>, B<-man>
  124.  
  125. Manual: print manual page.
  126.  
  127. =item B<-V>, B<-version>
  128.  
  129. Version: show version number.
  130.  
  131. =item B<-e>
  132.  
  133. Expression: code to act on files name.
  134.  
  135. May be repeated to build up code (like C<perl -e>).
  136. If no B<-e>, the first argument is used as code.
  137.  
  138. =item B<-E>
  139.  
  140. Statement: code to act on files name, as B<-e> but terminated by ';'.
  141.  
  142. =back
  143.  
  144. =head1 ENVIRONMENT
  145.  
  146. No environment variables are used.
  147.  
  148. =head1 AUTHOR
  149.  
  150. Larry Wall
  151.  
  152. =head1 SEE ALSO
  153.  
  154. mv(1), perl(1)
  155.  
  156. =head1 DIAGNOSTICS
  157.  
  158. If you give an invalid Perl expression you'll get a syntax error.
  159.  
  160. =head1 BUGS
  161.  
  162. The original
  163. C<rename>
  164. did not check for the existence of target filenames,
  165. so had to be used with care.
  166. I hope I've fixed that (Robin Barker).
  167.  
  168. =cut
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement