JournalMeSchoolFunstuffContact
Previous entry Next entry

Post-Thanksgiving Recap

November 25, 2007

come back farah

Woo for Thanksgiving! One of my favorite things about being home in Chicago is just sitting back . . . and relaxing. It's so easy to get caught up in the whole 'need to catch up on robbins pathology readings' and whatnot, so I guess it was refreshing to be at home with no med school textbooks (guessing the hyperventilation will catch up on Monday -- final exams in two weeks? @#$%!) Anyway, had a lovely time a few sci-fi / fantasy paperbacks and finally finishing up "Prince of Persia: Sands of Time" with A., (she's much better at those hideous 'box-moving' logic puzzles).

In any case, one thing I'm rather proud of is a new Perl script that I wrote that will help transfer a photo gallery from ACDSee to the web. I've been trying to get some photos organized, and while ACDSee has been most helpful (very fast, can rate and categorize photos), it can't export a photo gallery into hierarchical folders -- the best it can do is create files with a custom filename (i.e. "Places.Field Museum -- King Tut.jpg"). Now, the Perl script below will cycle through a directory with files named in the above fashion, and will automatically create folders and subfolders for the file, and place the file in its appropriate subfolder (i.e. "King Tut.jpg" is now in subfolder "Field Museum", which is in folder "Places"):

#!/usr/bin/perl
use File::Copy;

my $dirname = "C:/Misc/My Photos/Dump";
my $sortdir = "C:/Misc/My Photos/Sort";

opendir SOMEDIR, $dirname or die "Cannot open $dirname: $!";
while (my $name = readdir SOMEDIR) {
next if $name =~ /^\./; # skip over dot files
$name_short = $name;
$name = "$dirname/$name"; # patch up the path

$pos1 = rindex($name_short, "--");
$prefix = substr ($name_short, 0, $pos1);
$suffix = substr ($name_short, $pos1+3);

$prefix =~ s/\./\//;
$prefix_cycle = $prefix;

@array = split(/\//, $prefix);
$count = 1;
$newdir2 = $sortdir;
while ($count <= @array)
{
$newdir2 = "$newdir2/$array[$count-1]";
mkdir ($newdir2, 0777);
$count++;
}
$len_newdir2 = length($newdir2);
$newdir3 = substr($newdir2, 0, $newdir2-1);


$old_dir = "$dirname/$name_short";
$new_dir = "$newdir3/$suffix";


print("OLD is $old_dir NEW is $new_dir\n");
copy($old_dir, $new_dir) or die "File cannot be copied for real.";

next unless -f $name and -r $name; # only readable files
}

closedir SOMEDIR;

Anyway, once files are put into folders and subfolders, it's quite easy to use JAlbum to create a nicely formatted web gallery. Of course, the benefit of using ACDSee in the first place is that now it's very easy to select a few hundred photos that are rated above, say, 3 stars -- and be able to rebuild and upload a photo gallery from scratch within 10 minutes, instead of manually creating subfolders and dragging, resizing, and rotating photos using the Windows file manager.

Perl is a wonderful language to work with, and the Windows ActivePerl distribution made it easy to get everything working without much effort. In retrospect, I wish I learned Perl before doing PhD stuff (would have been able to easily pre-format statistical data files before loading them into SAS or STATA), but I guess better late than never :)