Created
January 11, 2019 07:09
-
-
Save sangheonhan/3415829ec57b670b2a0a0c3822722414 to your computer and use it in GitHub Desktop.
와우 스크린샷 파일 이름 정리
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use strict; | |
use warnings; | |
my @files = glob("*.jpg *.png *.tga"); | |
foreach ( @files ) { | |
my $new_filename_prefix; | |
my $new_filename_postfix; | |
my $file_extension; | |
my $new_screenshot_datetime; | |
if ( /^(\d{4})-(\d{2})-(\d{2}) (\d{2})-(\d{2})-(\d{2})/ ) { | |
# YYYY-MM-DD HH-II-SS 형식으로 생각되는 파일 이름은 건너뛴다 | |
next; | |
} | |
if ( /^(.*)WoWScrnShot_(\d{2})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})(.*)\.(\w+)$/ ) { | |
$new_screenshot_datetime = "20$4-$2-$3 $5-$6-$7"; | |
$new_filename_prefix = trim_dash($1); | |
$new_filename_postfix= trim_dash($8); | |
$file_extension = $9; | |
} | |
else { | |
print "$_ 파일의 스크린샷 일시를 알 수 없음\n"; | |
next; | |
} | |
my $new_filename; | |
$new_filename = $new_filename_prefix; | |
$new_filename .= " - " if ( length($new_filename_postfix) > 0); | |
$new_filename .= $new_filename_postfix; | |
$new_filename = $new_screenshot_datetime." ".$new_filename.".".$file_extension; | |
rename $_, $new_filename; | |
} | |
sub trim_dash { | |
my $s = shift; | |
if ( $s =~ /^\s*-\s*(.*)$/ ) { | |
$s = $1; | |
} | |
if ( $s =~ /^(.*?)\s*-\s*$/ ) { | |
$s = $1; | |
} | |
return $s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment