0

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.

We have a parent directory which is D:\ParentDir and inside ParentDir, 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.

let say

$dir = "D:\ParentDir" 
$file = "D:\ParentDir\subdir1\subdir2\subdir3\file1"

Here I want to write a PowerShell script to get the folder list between $dir and file1 like

$dir + n + file1 --> trying to get the folders list 'n'

In the above example, n is \subdir1\subdir2\subdir3

Is there any way to get that information ?

karthik
  • 417
  • 1
  • 7
  • 15
  • Does this answer your question? [Get relative path of files in sub-folders from the current directory](https://stackoverflow.com/questions/10972589/get-relative-path-of-files-in-sub-folders-from-the-current-directory) – iRon May 08 '21 at 10:57
  • Thank you for the article but this did not help to fix the issue. The given article only provides the information if we know the sub-directory path. The agenda of my script is find the sub-directories between the parent directory and the file – karthik May 08 '21 at 11:06

1 Answers1

0
Set-Location $dir
$file |Split-Path |Resolve-Path -Relative
iRon
  • 20,463
  • 10
  • 53
  • 79