#!/usr/local/bin/perl eval "exec perl -S $0 $*" if $running_under_some_shell; # # Matt Schwab 25Sep95 # $usage = " Usage: $0 dir Usage: $0 link\n"; $selfdoc = " copies all linked files in the subdirectory tree. Thereby removing the links.\n"; if ($#ARGV < 0 ||$#ARGV > 1 ) { print $usage; die $selfdoc; } &decision($ARGV[0]); sub decision{ local($file) = @_; if ( -d $file ){&subdir($file);} elsif( -l $file ){©fl($file);} elsif( -f $file ){print "$file is a plain file. I do nothing.\n";} else {print "$file is not a link nor directory\n"; die $usage;} } sub subdir{ local($dir) = @_; # print "directory: $dir\n"; chdir $dir; opendir(DIR,'.') || die "Can't open dir: $dir\n"; local(@filenames) = readdir(DIR); closedir(DIR); for(@filenames) { local($file) = $_; next if $file eq '.'; next if $file eq '..'; # print "subdir: $file\n"; &decision($file); } chdir '..'; } sub copyfl{ local($file) = @_; local($tmpfile); $tmpfile = "$file.junk"; print "copy $tmpfile\n"; `/bin/cp $file $tmpfile`; `/bin/rm -f $file`; `/bin/mv $tmpfile $file`; `/bin/chmod ug+rw $file`; }