commit
This commit is contained in:
35
script.sh
Normal file
35
script.sh
Normal file
@@ -0,0 +1,35 @@
|
||||
#!bash
|
||||
|
||||
PERL_SCRIPT=$(cat <<'EOF'
|
||||
@files = split(/:/, $ARGV[0]);
|
||||
@new_files = ();
|
||||
foreach $file (@files) {
|
||||
if ($file =~ m#^\./.+\.(jpe?g|png|gif)$#) {
|
||||
($mtime) = (stat($file))[9];
|
||||
$ext = $1;
|
||||
$new_file = "./$mtime.$ext";
|
||||
if ($new_file eq $file) {
|
||||
next;
|
||||
}
|
||||
while (grep $_ eq $new_file, @new_files) {
|
||||
if (! defined $suffix) {
|
||||
$suffix = "-1";
|
||||
} else {
|
||||
$suffix = $suffix - 1;
|
||||
}
|
||||
$new_file = "./$mtime$suffix.$ext";
|
||||
}
|
||||
push(@new_files, $new_file);
|
||||
$file =~ s#([ \(\)])#\\$1#g;
|
||||
print "mv -n \"$file\" $new_file\n";
|
||||
undef $suffix;
|
||||
}
|
||||
}
|
||||
$count = @new_files;
|
||||
print "echo \"Renamed: $count\"\n";
|
||||
EOF
|
||||
)
|
||||
|
||||
renamer() {
|
||||
find . -maxdepth 1 -type f -print | tr '\n' ':' | xargs -I{} -- perl -e "$PERL_SCRIPT" '{}' | xargs -n1 -I{} -- bash -c '{}'
|
||||
}
|
||||
Reference in New Issue
Block a user