in reply to Checking subdirectories in a given path
use strict; use warnings; use File::Spec::Functions qw/ canonpath /; my $fullpath = '/www/stage/sites/MyCompany/docs/systems/./foo/../docum +entation///'; my $sitedoc = '/www/stage/sites/MyCompany/docs/..'; my $want = 'config.cfg'; print find_file($fullpath, $sitedoc, $want) ? "found" : "not found"; sub find_file { my ($path, $root, $want) = @_; $path = canonpath($path); $root = canonpath("$root/.."); my $found; while ($path ne $root) { $found = 1, last if -f "$path/$want"; $path =~ s!\\[^\\]+$!!; } return $found; }
|
|---|