Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #script to show and/or fix wrong filenames in my music folder.
- #by $uicide
- use warnings;
- use strict;
- my $replace = 0;
- my $show = 0;
- my $help = 1;
- foreach (@ARGV) {
- $help = 0;
- if($_ eq "--rename")
- {
- $replace = 1;
- }
- if($_ eq "--show")
- {
- $show = 1;
- }
- if($_ eq "--help")
- {
- $help= 1;
- }
- }
- if($help == 1)
- {
- print "Usage:\n./fix.pl [--show] [--raname]\n";
- }
- if($show == 1)
- {
- process_files (".");
- }
- sub process_files {
- my $dirname = shift;
- #print "DIR: $dirname\n";
- opendir(DIR, $dirname) or die "can't opendir $dirname: $!";
- my @files = grep { !/^\.{1,2}$/ } readdir (DIR);
- #while (defined(my $file = readdir(DIR)))
- for (@files)
- {
- my $file = $_;
- # do something with "$dirname/$file"
- #next if $file =~ m/^\.{1,2}$/;
- if (-d "$dirname/$file") {
- if($replace ==1)
- {
- print "\nAlbum: $dirname/$file \n";
- }
- process_files("$dirname/$file");
- }
- next unless $file =~ m/^(\d*)\s([^-])(.*)$/;
- if(defined($2) && defined($1) && defined($3))
- {
- if($2 ne "")
- {
- if($replace ==1)
- {
- rename("$dirname/$file", "$dirname/$1 - $2$3");
- }
- #print "\n\t$file\n";
- if($replace ==0)
- {
- print $dirname;
- }
- print "\t$1 - $2$3\n";
- }
- }
- }
- closedir(DIR);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement