Created
June 10, 2012 10:39
-
-
Save yasuoza/2904907 to your computer and use it in GitHub Desktop.
Image file exist checker.
This file contains 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
#!env perl | |
use strict; | |
use warnings; | |
use feature qw/say/; | |
use Text::CSV_XS; | |
use DateTime; | |
#CSV file | |
my $csv_file = $ARGV[0]; | |
my $csv = Text::CSV_XS->new({binary => 1}); | |
#Image extname | |
my $EXT = ".jpg"; | |
# If no csv filename, we exit this program. | |
if (!defined($csv_file)) { | |
say "Error! Enter csv filename!"; | |
exit; | |
} | |
if (! -e $csv_file) { | |
say "Error! There is no such file $csv_file"; | |
exit; | |
} | |
my @images_array; | |
my $row_counter = 0; | |
open my $fh, "< $csv_file" or die "$csv_file: $!"; | |
while (my $row = $csv->getline($fh)) { | |
if ($row_counter == 0) { | |
$row_counter++; | |
next; | |
} | |
push @images_array, $row->[0]; | |
} | |
close $fh; | |
exit if $#images_array == 0; | |
my @unknow_image_array; | |
foreach my $image_name (@images_array) { | |
if (! -e "./images/$image_name" . $EXT) { | |
push @unknow_image_array, $image_name; | |
} | |
} | |
exit if scalar(@unknow_image_array) == 0; | |
my $dt = DateTime->now( time_zone => 'Asia/Tokyo' ); | |
my $file_title = $dt->ymd('') . qw{_} . $dt->hms('') . qw{_unknow_images}; | |
open my $ffh, ">> $file_title.txt"; | |
foreach my $unknow_image_name (@unknow_image_array) { | |
say $ffh "$unknow_image_name" . $EXT; | |
} | |
close $ffh; | |
say "There is unknown image! See log file $file_title.txt"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment