Report folders which have a specific subfolder

99封情书 提交于 2019-12-13 03:48:26

问题


I am building a script which I use to deploy files to multiple specific folders. The destination folders are collected using this part.

$destinations = Get-ChildItem "C:\this\is\*\my\path\" 

So my script replaces only if the folder has the subfolders "\my\path\"

If I now check my variable it will return the fullpathes but I only need the folder name. I tried using select -path to show at least only the path but it returned as well the length, mode etc.

my goal is to return only values like this:

folder 1
folder 2
folder 3

I am using powershell 3.0


回答1:


So if we are checking for folders that have the child structure folder1\folder2 where the parent folder is in C:\Temp then we would do something like this:

$destinations = (Get-Item "C:\Temp\*\folder1\folder2").Parent.Parent.Name

Get-Item "C:\Temp\*\folder1\folder2" would just return System.IO.DirectoryInfo objects for folder2. We take those objects and find their grandparent folders and just return their names only.



来源:https://stackoverflow.com/questions/29351035/report-folders-which-have-a-specific-subfolder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!