Trying to figure out how this File::Spec and Cwd thing works.
This commit is contained in:
@@ -5,13 +5,16 @@ use strict;
|
||||
|
||||
use File::Find::Wanted;
|
||||
use File::Basename;
|
||||
use Cwd qw/ realpath abs_path /;
|
||||
use File::Spec;
|
||||
use File::Spec::Functions;
|
||||
use Image::EXIF;
|
||||
use Data::Dumper::Simple;
|
||||
use Math::Round;
|
||||
|
||||
my $conf = {
|
||||
src_dir => "./pics",
|
||||
dst_dir => "./links",
|
||||
src_dir => "pics",
|
||||
dst_dir => "links",
|
||||
};
|
||||
|
||||
# verify the source dir
|
||||
@@ -95,7 +98,8 @@ print "Aspect ratio information for all images (aspect ratio => number of occure
|
||||
print Dumper $ars;
|
||||
print "\n";
|
||||
|
||||
# Create destination directories
|
||||
# Create destination directories. TODO: use something smarter than just string
|
||||
# concatenation.
|
||||
print "Creating destination directories: ";
|
||||
foreach my $d (keys %$ars) {
|
||||
my $dirname = $conf->{dst_dir} . "/" . $d;
|
||||
@@ -109,14 +113,19 @@ print "Symlinking source files into destination directories.\n";
|
||||
foreach my $f (keys %$files) {
|
||||
next unless exists $files->{$f}->{ar};
|
||||
|
||||
# construct the symlink name
|
||||
# Construct the symlink path. TODO: use something smarter than just string
|
||||
# concatenation.
|
||||
my $name = basename($f);
|
||||
my $ar = $files->{$f}->{ar};
|
||||
my $dest = $conf->{dst_dir} . "/" . $ar . "/" . $name;
|
||||
my $symlink = $conf->{dst_dir} . "/" . $ar . "/" . $name;
|
||||
|
||||
# Costruct the relative path that the symlink points to
|
||||
my $path = File::Spec->abs2rel(realpath($f), realpath($symlink));
|
||||
|
||||
print "f='$f' symlink='$symlink' path='$path' abs_path(f)='" . abs_path($f) . "'\n";
|
||||
|
||||
# symlink
|
||||
print "$f -> $dest\n";
|
||||
symlink($f, $dest);
|
||||
print "symlink($path, $symlink);\n";
|
||||
}
|
||||
|
||||
# vim: set ts=4 sw=4 et cc=80:
|
||||
|
||||
Reference in New Issue
Block a user