You could probably:
cd to dir1
getcwd
cd to dir2
getcwd
repeat
cd ..
getcwd
if getcwd == dir1's cwd, then under
until at /
cd to dir1
repeat
cd ..
getcwd
if getcwd == dir2's cwd, then under
until at /
This should deal with symlinks and junctions, as long as you aren't worried
Hi Thomas,
Thomas Jollans wrote:
> On 07/11/2010 03:37 PM, Gelonida wrote:
>> #
>> import os
>> def is_below_dir(fname,topdir):
>> relpath = os.path.relpath(fname,topdir)
>> return not relpath.startswith('..'+os.sep)
>>
>> print is_below_dir(
On 07/11/2010 03:37 PM, Gelonida wrote:
> #
> import os
> def is_below_dir(fname,topdir):
> relpath = os.path.relpath(fname,topdir)
> return not relpath.startswith('..'+os.sep)
>
> print is_below_dir(path1,path2)
> ###
Hi,
I wanted to figure out whether a given path name is below another path name.
Surprisingly this turned out to be more difficult than initially
anticipated:
Let's assume I want to find out, whether path1 is below path2
First I thought about checking whether
path1 starts with path2
For this