change the file date and time

Frank Shute frank at shute.org.uk
Sat Jun 7 03:15:42 UTC 2008


On Fri, Jun 06, 2008 at 08:25:41PM +0300, Georgi Tyuliev wrote:
>
> Dear Sirs
> 1. How to mount Sony Ericsson k750i mobile phone with FreeBSD 7.0 ?

Plug it in and see what shows up in /var/log/messages. Then read the
handbook:

http://www3.uk.freebsd.org/doc/en_US.ISO8859-1/books/handbook/usb-disks.html

> 2. How to change automatically the file attributes (for example
> 'date') of large number of files?  For example: I have taken many
> photos with my Sony Ericsson k750i mobile phone and the exact time
> end date is accessible (e.g. through F3 of the midnight commander),
> but very often when copying the jpg's the file attributes change.

If you're lucky, the jpg's will contain exif info which if the
phone's time & date is set will tell you when the picture was taken
amongst other things.

This is more reliable than depending on file date.

Here's a quick & dirty perl script (called picinfo) that I used to get
this data (modify at your will):

<------------>

#!/usr/bin/perl -w
#
# Print tab delimited exif data from an image file suitable for
# insertion into a DB.
#
# Takes file as arg.
#
# Usage example:
#
#      $  for file in $(ls | grep 'jpg');do
#      $  picinfo $file >> ~/data.txt
#      $  done

use Image::Info qw(image_info);


# Get exif data as a hash

my $info = image_info($ARGV[0]);


# Pic mangled or exif data doesn't exist

if (my $error = $info->{error}) {
        die "Can't parse image info: $error\n";
        }


# Get data from hash

my $my_date = $info->{DateTimeOriginal};  # iso format date/time.
my $my_exptime = $info->{ExposureTime};   # reciprocal of speed in secs
                                          # as a rational no.
my $my_fstop = $info->{FNumber};          # fstop as a rational no.
my $my_asa = $info->{ISOSpeedRatings};    # ASA


# Grab date

my $the_date = substr($my_date, 0, 10);


# Grab time

my $the_time = substr($my_date, -8);


# Doh! Camera date/time not set.

if ($the_date eq "0000:00:00") {
	$the_date = "N/K";
	}

if ($the_time eq "00:00:00") {
	$the_time = "N/K";
	}


# Call sub-funcs

$my_fstop = fstop();
$my_exptime = speed();

print "$ARGV[0]\t$the_date\t$the_time\t$my_exptime\tF$my_fstop\t$my_asa\n";


###___SUBS___###


sub fstop{

$my_fstop =~ s/\/10//;
$my_fstop = $my_fstop/10;
return $my_fstop;

}


sub speed{

my $divisor = $my_exptime;
my $numerator = $my_exptime;

$divisor =~ s/[0-9]+\/([0-9]+)/$1/;
$numerator =~ s/([0-9]+)\/[0-9]+/$1/;

#print "divisor = $divisor\n";
#print "num = $numerator\n";

$my_exptime = $numerator/$divisor;     # Calc exposure in decimal

my $exposure = 0;

# Horrendous case statement. Is there a better way to do this?

SWITCH: {
	if ($my_exptime <= 0.00033) {
		 $exposure = "< 1/3000";
		last SWITCH;
		}
	if ($my_exptime <= 0.0005) {
		 $exposure = "1/2000";
		last SWITCH;
		}
	if ($my_exptime <= 0.001) {
		 $exposure = "1/1000";
		last SWITCH;
		}
	if ($my_exptime <= 0.00125) {
		 $exposure = "1/800";
		last SWITCH;
		}
	if ($my_exptime <= 0.00167) {
		 $exposure = "1/600";
		last SWITCH;
		}
	if ($my_exptime <= 0.002) {
		 $exposure = "1/500";
		last SWITCH;
		}
	if ($my_exptime <= 0.0025) {
		 $exposure = "1/400";
		last SWITCH;
		}
	if ($my_exptime <= 0.0033) {
		 $exposure = "1/300";
		last SWITCH;
		}
	if ($my_exptime <= 0.005) {
		 $exposure = "1/200";
		last SWITCH;
		}
	if ($my_exptime <= 0.01) {
		 $exposure = "1/100";
		last SWITCH;
		}
	if ($my_exptime <= 0.0167) {
		 $exposure = "1/60";
		last SWITCH;
		}
	if ($my_exptime <= 0.033) {
		 $exposure = "1/30";
		last SWITCH;
		}
	if ($my_exptime <= 0.05) {
		 $exposure = "1/20";
		last SWITCH;
		}
	if ($my_exptime <= 0.0625) {
		 $exposure = "1/16";
		last SWITCH;
		}
	if ($my_exptime <= 0.125) {
		 $exposure = "1/8";
		last SWITCH;
		}
	if ($my_exptime <= 0.25) {
		 $exposure = "1/4";
		last SWITCH;
		}
	if ($my_exptime <= 0.5) {
		 $exposure = "1/2";
		last SWITCH;
		}
	if ($my_exptime <= 1) {
		 $exposure = "1";
		last SWITCH;
		}
	if ($my_exptime <= 2) {
		 $exposure = "2";
		last SWITCH;
		}
	$exposure = "> 2";
	}
return $exposure;
}

<------------>

Last time I used it, it worked.  You'll have to have
graphics/p5-Image-Info installed though.

> Best regards,
> G.Tyuliev

Regards,

-- 

 Frank 


 Contact info: http://www.shute.org.uk/misc/contact.html 



More information about the freebsd-questions mailing list