报告具有特定子文件夹的文件夹 [英] Report folders which have a specific subfolder
问题描述
我正在构建一个脚本,该脚本用于将文件部署到多个特定的文件夹. 使用此部分收集目标文件夹.
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\"
因此,仅当文件夹包含子文件夹"\ my \ path \"时,我的脚本才会替换
So my script replaces only if the folder has the subfolders "\my\path\"
如果现在检查我的变量,它将返回完整路径,但是我只需要文件夹名称.我尝试使用select -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
我正在使用Powershell 3.0
I am using powershell 3.0
推荐答案
因此,如果我们要检查具有子结构folder1\folder2
的文件夹,其中父文件夹位于C:\Temp
中,那么我们将执行以下操作:
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"
只会为folder2
返回System.IO.DirectoryInfo
个对象.我们拿走那些对象,找到它们的祖父母文件夹,只返回它们的名字.
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.
这篇关于报告具有特定子文件夹的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!