$webpath = '/some/long/path/to_be/fixed/' ; if ( ! -d "$webpath/" ) { my $fixcnt = fixdir("$webpath/"); print "fixed ",$fixcnt," directories\n"; } sub fixdir { # # written 7/11/05 # accepts a (invalid) directory, then goes up the dir tree until a folder exists, then # goes back down the tree creating new folders by depth # my $dir = shift; $dir =~ s/\/$//g; my @path = split(/\//, $dir); #print "count=", $#path, "\n"; my @test = @path; my $test = join( '/', @path); #print $test, "\n"; my $j=0; while ( ! -d $test ) { $j++; pop(@test) ; $test = join( '/', @test); # print $test, "\n"; last if ($j > $#path-2); } print "cnt=$j\n"; for my $k (1 .. $j ) { print $test . '/' . $path[-($j-$k+1)] . "\n"; mkdir($test . '/' . $path[-($j-$k+1)] ) or warn "failed to make dir\n"; $test .= '/' . $path[-($j-$k+1)] } return $j; }