title: How to find the folders list present between a parent directory and a file created inside many nested subdirectories inside the parent directory
body: <p>I am working on to build an automation using Powershell to maintain the proper directory architecture for each individual file inside a server and track them with a record.</p>
  <p>We have a parent directory which is <em>D:\ParentDir</em> and inside <em>ParentDir</em>, we do have multiple nested subdirectories. All here I am trying to get is, if I pick up a file inside these sub directories, what are the sub-directories behind the file from the Parent Directory.</p>
  <p>let say</p>
  <pre><code>$dir = &quot;D:\ParentDir&quot; 
  $file = &quot;D:\ParentDir\subdir1\subdir2\subdir3\file1&quot;
  </code></pre>
  <p>Here I want to write a PowerShell script to get the folder list between $dir and file1 like</p>
  <p><code>$dir + n + file1</code> --&gt; trying to get the folders list 'n'</p>
  <p>In the above example, n is \subdir1\subdir2\subdir3</p>
  <p>Is there any way to get that information ?</p>