X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=torn;h=36d8c8f10bee2e2b0eda96a315866f68481711db;hb=252fae71d79309d40494ffa22cecfe4e48ee87bc;hp=e1f1cfc0d5eeacaae75bcb55e37a79ee13d30410;hpb=66b4184a4272f672eb4e865fa2bd7c6869a724d5;p=torn.git diff --git a/torn b/torn index e1f1cfc..36d8c8f 100755 --- a/torn +++ b/torn @@ -1,6 +1,6 @@ #!/usr/bin/env perl # torn - Musical files renaming with russian language transliteration -# Copyright (C) 2007-2020 Sergey Matveev (stargrave@stargrave.org) +# Copyright (C) 2007-2021 Sergey Matveev (stargrave@stargrave.org) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,7 +25,8 @@ files and rules to convert russian filenames to translit. =head1 USAGE Simply run this script in directory where you want files and/or -directorires to be renamed. +directories to be renamed. Directories are not transliterated by +default, but you can use FORCE_DIR=1 environment variable. =head1 OVERVIEW @@ -59,14 +60,14 @@ use Encode; binmode STDOUT, ":utf8"; -my $VERSION = "0.9"; +my $VERSION = "0.10"; my $src; my $dst; my $src_filename; if ($#ARGV >= 0) { - print "torn version $VERSION, Copyright (C) 2007-2020 Sergey Matveev + print "torn version $VERSION, Copyright (C) 2007-2021 Sergey Matveev torn comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.\n Usage: just run inside the directory. Look for POD inside the script itself.\n"; @@ -76,7 +77,7 @@ opendir DIR, "." or die "Can not open directory\n"; foreach (sort readdir DIR) { # Skip directory itself next if /^\.{1,2}$/; - next if -d; + next if -d and not $ENV{FORCE_DIR}; $src_filename = $_; $src = decode "utf-8", $src_filename; @@ -117,13 +118,13 @@ foreach (sort readdir DIR) { }; # Change looking of track numbers - # And renaming itself - if($dst =~ /^(\d+)\-(.+)$/){ - print "$src -> $1.$2\n"; - rename $src_filename, "$1.$2"; - } else { - print "$src -> $dst\n"; - rename $src_filename, $dst; + if ($dst =~ /^(\d+)[-.]_*(.+)$/) { + $dst = "$1.$2"; }; + + next if ($src_filename eq $dst); + print "$src -> $dst\n"; + die "\"$dst\" exists" if -e $dst; + rename $src_filename, $dst; }; closedir DIR;