wintoid
4th of April 2004 (Sun), 14:49
Hope noone minds me posting this here, I just wanted to share.
I've recently made the move to Linux, and one of the things holding me back has been getting images off my compactflash card reader. I wanted a script that would make subdirectories like Downloader Pro does, based on the date of the file. I couldn't find anything that would do that on the net, so I decided to write my own in Perl. I should warn you, I don't actually know Perl, although I have a lot of experience with other languages, so a bit of creative thinking got this working for me.
The following script which I called "image_scoop.pl" is set up to copy any Canon raw files found below the /media directory to my /data/G1Photos directory. Anyone using this script would have to change those 2 directories to represent their own card reader and destination image directory accordingly.
I'd love it if someone found this useful, but I provide no warranty whatsoever.
#!/usr/bin/perl
use File::Find;
use File::stat;
print "Image Scoop starting\n";
find(\&copy_files, "/media");
print "Image Scoop done\n";
sub copy_files()
{
if ( (/\.crw$/) || (/\.CRW$/) ) {
$sb = stat($_) or die "Unable to stat $_\n";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) =
localtime $sb->mtime;
$date8 = sprintf("%04d-%02d-%02d", $year+1900, $mon+1, $mday);
$dir = dir_name($date8);
print "Copying $File::Find::name to $dir\n";
$copy = `cp -f $File::Find::name $dir\/`;
}
}
sub dir_name($)
{
$date8 = $_[0];
$fulldir="\/data\/G1Photos\/$date8";
$found = "true";
@stats = stat($fulldir) or $found = "false";
if ( $found eq "false" )
{
# the dir doesn't exist yet, so create it.
print "Creating directory $fulldir\n";
mkdir ("$fulldir");
}
return $fulldir;
}
I've recently made the move to Linux, and one of the things holding me back has been getting images off my compactflash card reader. I wanted a script that would make subdirectories like Downloader Pro does, based on the date of the file. I couldn't find anything that would do that on the net, so I decided to write my own in Perl. I should warn you, I don't actually know Perl, although I have a lot of experience with other languages, so a bit of creative thinking got this working for me.
The following script which I called "image_scoop.pl" is set up to copy any Canon raw files found below the /media directory to my /data/G1Photos directory. Anyone using this script would have to change those 2 directories to represent their own card reader and destination image directory accordingly.
I'd love it if someone found this useful, but I provide no warranty whatsoever.
#!/usr/bin/perl
use File::Find;
use File::stat;
print "Image Scoop starting\n";
find(\&copy_files, "/media");
print "Image Scoop done\n";
sub copy_files()
{
if ( (/\.crw$/) || (/\.CRW$/) ) {
$sb = stat($_) or die "Unable to stat $_\n";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) =
localtime $sb->mtime;
$date8 = sprintf("%04d-%02d-%02d", $year+1900, $mon+1, $mday);
$dir = dir_name($date8);
print "Copying $File::Find::name to $dir\n";
$copy = `cp -f $File::Find::name $dir\/`;
}
}
sub dir_name($)
{
$date8 = $_[0];
$fulldir="\/data\/G1Photos\/$date8";
$found = "true";
@stats = stat($fulldir) or $found = "false";
if ( $found eq "false" )
{
# the dir doesn't exist yet, so create it.
print "Creating directory $fulldir\n";
mkdir ("$fulldir");
}
return $fulldir;
}