use Cwd; # module for finding the current working directory $|=1; # turn off I/O buffering sub ScanDirectory { my ($workdir) = shift; my($startdir) = &cwd; # keep track of where we began chdir($workdir) or die "Unable to enter dir $workdir:$!\n"; if($first == 0) { $wholeTarget = &cwd; $wholeTargetLen = length($wholeTarget); $first = 1; } opendir(DIR, ".") or die "Unable to open $workdir:$!\n"; my @names = readdir(DIR); closedir(DIR); foreach my $name (@names){ next if ($name eq "."); next if ($name eq ".."); if (-d $name){ $relname = &cwd."/".$name; $diff = substr($relname,$wholeTargetLen); $targetName = $stubDir.$diff; mkdir($targetName); &ScanDirectory($name); next; } &CreateStub($name); } chdir($startdir) or die "Unable to change to dir $startdir:$!\n"; } sub CreateStub{ my($name) = shift; $relname = &cwd."/".$name; $diff = substr($relname,$wholeTargetLen); $targetName = $stubDir.$diff; $relname = $stubRelDir."/".$name; #print $relname."\n"; unless (open(T,">$targetName")) { print "cant do ".$diff."\n"; return 0; } print T "" ."" ."" ." Stub for ".$relname."" ."" ."" ."

Stub for ".$relname ."

" ."

This is a stub for ".$relname ."

" ."" .""; close(T); return 1; } my $count = $#ARGV + 1; $wholeTargetLen = "0"; $wholeTarget = "/home"; $stubRelDir = $ARGV[0]; $stubDir = &cwd."/".$ARGV[0]."-stub"; $first = 0; if ($count < 1 || $ARGV[0] eq "-h" || $ARGV[0] eq "--help") { print "\nUsage: perl generateStubs.pl [sub-directory to stub]\n"; print "**** WARNING: the argument MUST be a subdirectory\n"; die "Recommended: go to the parent directory of the one you want to generate stubs for and do: perl generateStubs.pl myDirectory \n"; } mkdir($stubDir); &ScanDirectory($ARGV[0]);