Last change
on this file since 29106 was 29106, checked in by jmt12, 10 years ago |
Check-in of script to symlink lorem files to matching files in another directory...
|
-
Property svn:executable
set to
*
|
File size:
1.5 KB
|
Line | |
---|
1 | #!/usr/bin/perl
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 | use warnings;
|
---|
5 |
|
---|
6 | if (!defined $ARGV[0] || !-d $ARGV[0])
|
---|
7 | {
|
---|
8 | &printUsage('Missing source directory');
|
---|
9 | }
|
---|
10 | my $source_dir = $ARGV[0];
|
---|
11 | if (!defined $ARGV[1] || !-d $ARGV[1])
|
---|
12 | {
|
---|
13 | &printUsage('Missing target directory');
|
---|
14 | }
|
---|
15 | my $target_dir = $ARGV[1];
|
---|
16 |
|
---|
17 | print "====== Linkinator ======\n";
|
---|
18 | print "Replaces files in <target dir> with links if they are also found in\n";
|
---|
19 | print "<source dir>.\n\n";
|
---|
20 | &recursivelyScan($source_dir, $target_dir);
|
---|
21 | print "====== Complete! ======\n\n";
|
---|
22 | exit;
|
---|
23 |
|
---|
24 | sub printUsage
|
---|
25 | {
|
---|
26 | my ($msg) = @_;
|
---|
27 | if (defined $msg)
|
---|
28 | {
|
---|
29 | print "Error! $msg\n";
|
---|
30 | }
|
---|
31 | print "Usage: linkinator.pl <source dir> <target dir>\n\n";
|
---|
32 | exit;
|
---|
33 | }
|
---|
34 |
|
---|
35 | sub recursivelyScan
|
---|
36 | {
|
---|
37 | my ($sdir, $tdir) = @_;
|
---|
38 |
|
---|
39 | print " * Comparing: " . $tdir . " => " . $sdir . "\n";
|
---|
40 |
|
---|
41 | opendir(DH, $tdir);
|
---|
42 | my @files = readdir(DH);
|
---|
43 | closedir(DH);
|
---|
44 |
|
---|
45 | foreach my $file (@files)
|
---|
46 | {
|
---|
47 | if ($file !~ /^\./)
|
---|
48 | {
|
---|
49 | my $spath = $sdir . '/' . $file;
|
---|
50 | my $tpath = $tdir . '/' . $file;
|
---|
51 | if (-d $tpath && -d $spath)
|
---|
52 | {
|
---|
53 | &recursivelyScan($spath, $tpath);
|
---|
54 | }
|
---|
55 | elsif (-f $tpath && -f $spath)
|
---|
56 | {
|
---|
57 | print " - symlinking: " . $file . "\n";
|
---|
58 | unlink($tpath);
|
---|
59 | link($spath, $tpath);
|
---|
60 | }
|
---|
61 | elsif (-f $tpath)
|
---|
62 | {
|
---|
63 | print " - only in target: " . $file . "\n";
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.