Re: How to check if something is a sub-directory?



On Fri, 29 Feb 2008 00:44:18 +0100, laredotornado@xxxxxxxxxxx <laredotornado@xxxxxxxxxxx> wrote:

Hi,

Is there a more sophisticated way, beyond the "strstr" function, to
check if $dir1 is a sub-directory of $dir2, both being strings? You
may assume that both are absolute paths.

If it is direct 'descendant':
$is_subdir = realpath($dir1.'/..') == realpath($dir2);

If not, still apply realpath, but check with either a regex or a substring that the 'parent'-path is indeed at the START of the 'child'-path.
--
Rik Wasmus
.



Relevant Pages

  • How to check if something is a sub-directory?
    ... check if $dir1 is a sub-directory of $dir2, both being strings? ...
    (comp.lang.php)
  • [perl-python] a program to delete duplicate files
    ... prints the full paths of all files in dir1 that are duplicate. ... line follows a group of duplicates. ... will do the same as above, except that duplicates within dir1 or dir2 ... in dir2 does not matter) Note, although dir2 doesn't compare files ...
    (comp.lang.perl.misc)
  • [perl-python] a program to delete duplicate files
    ... prints the full paths of all files in dir1 that are duplicate. ... line follows a group of duplicates. ... will do the same as above, except that duplicates within dir1 or dir2 ... in dir2 does not matter) Note, although dir2 doesn't compare files ...
    (comp.lang.python)
  • Re: Track Hard drive Events
    ... created in dir2 was the file.ext that was deleted from dir1, ... how to react to the following windows events: ... for whatever file is located at least on the local hard drives (would be ...
    (microsoft.public.vb.winapi)
  • Re: how to find files not in other directory (effectively)?
    ... dir1 and dir2. ... is a fairly portable way to test if pathname exists. ... If names may contain newlines, it gets a bit trickier - as one also ...
    (comp.unix.shell)