Category: | Utility scripts |
Author/Contact Info | Brent Dax <brent@brentdax.com> |
Description: | For a Web project using Embperl, I have to show a small, fixed set of pages with several different templates (base.epl scripts, essentially, although I used a different extension). I chose to do this by creating hard links between the content files in each directory. crosslink.pl (or whatever you choose to call it) takes a source directory, a destination directory, and a list of files. It then runs link("sourcedir/filename", "destdir/filename") (or symlink) on each file. This allows me to do things like: crosslink template1 template2 index.epl bio.epl links.epl images/picture.jpg |
#!/usr/bin/perl
use strict;
use warnings;
if(@ARGV < 3) {
print <<"END";
Usage: $0 [options] srcdir destdir file1 [file2 [file3 [...]]]
Hard links given files in destdir to originals in srcdir.
Options:
-s Use soft links
-v Verbose--list each file as it's linked
END
exit;
}
my %opts;
$opts{pop @ARGV}=1 while $ARGV[0] =~ /^-/;
my($srcdir, $destdir, @files)=@ARGV;
for(@files) {
do_link("$srcdir/$_", "$destdir/$_") or die "Can't link $srcdir/$_
+ to $destdir/$_: $!";
print "$srcdir/$_ -> $destdir/$_\n" if $opts{-v};
}
sub do_link {
if($opts{-s}) {
return symlink($_[0], $_[1]);
}
else {
return link($_[0], $_[1]);
}
}
|
|
---|
Replies are listed 'Best First'. | |
---|---|
•Re: Crosslink
by merlyn (Sage) on Feb 02, 2004 at 11:38 UTC | |
by BrentDax (Hermit) on Feb 02, 2004 at 15:04 UTC | |
by Rich36 (Chaplain) on Feb 02, 2004 at 18:57 UTC |
Back to
Code Catacombs