File: rename.pl

package info (click to toggle)
libimage-exif-perl 2.01-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 412 kB
  • sloc: ansic: 5,025; perl: 375; makefile: 8
file content (41 lines) | stat: -rwxr-xr-x 722 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl -w

# author : sergey s prozhogin (ccpro@rrelaxo.org.ru)
# script renames file by EXIF date
# for information start perl rename.pl
#
# v 1.3 May-20-2004
#

use strict;
use Image::EXIF;
use Date::Parse;
use Data::Dumper;

my @list = `ls -1 *JPG *jpg *jpeg *JPEG`;

my $exif = new Image::EXIF;

for my $fname (@list)
{
	chomp $fname;

	$exif->file_name($fname);
	my $data = $exif->get_all_info();

	if ($data)
	{
		my $timestamp = $data->{image}->{'Image Created'} || $data->{other}->{'Image Generated'};
		my $time = str2time($timestamp);

		$timestamp = sprintf "%x", $time;

		my $count = 0;
		while (-f "img_$timestamp$count.jpg")
		{
			$count ++;
		}

		rename $fname, "img_$timestamp$count.jpg";
	}
}