Skip to content

Instantly share code, notes, and snippets.

@moccos
Created November 10, 2012 21:12
Show Gist options
  • Save moccos/4052512 to your computer and use it in GitHub Desktop.
Save moccos/4052512 to your computer and use it in GitHub Desktop.
[Perl] Rename downloaded file like "file(1).zip"
#!/usr/bin/perl
while(1) {
foreach(<*(1)*>) {
next if (/\.crdownload$/);
/(\S+)\s?\(\d\)(\.[^\.]+)?$/;
$new_name = "$1$2";
if (rename($_, $new_name)) { print "$_ -> $new_name\n"; }
#else { print STDERR "failed to rename: $_"; }
}
sleep(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment