我正在构建一个脚本,该脚本用于将文件部署到多个特定的文件夹. 使用此部分收集目标文件夹.
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.NameGet-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.
更多推荐
报告具有特定子文件夹的文件夹
发布评论