I am having a simple problem that I cannot figure out: I want to find a parent folder that contains a certain file, and generate an absolute path of that parent folder - and this needs to be done inside a batch script - no powershell, no perl, no python...

Example, say this is my directory tree:

```
  root_parent_path
    dir0
    dir1
      file1
      dir2
        dir21
        dir22
      dir3
        dir31
        dir32

```

In example above, `root_parent_path` is in form `c:\folder1\folder2\`.

The result should be stored in an environment variable, say RESULT\_PATH.

So if I call any of the following:

```
script.batch file1 root_parent_path\dir1\dir2
script.batch file1 root_parent_path\dir1\dir2\dir21
script.batch file1 root_parent_path\dir1\dir3\dir31

```

the variable RESULT\_PATH should be set to `root_parent_path\dir1`, because that is a parent that contains that `file1`. (I don't care if there is more then one or no parent folder - I will make sure there is only one.)

Help is much appreciated, so much time has been wasted on this...

Note: I would appreciate if code is also explained! If two answers offer working solution, I will pick up the one with better explanation.