具有特定子文件夹的报告文件夹
Report folders which have a specific subfolder
我正在构建一个脚本,用于将文件部署到多个特定文件夹。
使用此部分收集目标文件夹。
$destinations = Get-ChildItem "C:\this\is\*\my\path\"
所以我的脚本只有在文件夹有子文件夹“\my\path\”
时才会替换
如果我现在检查我的变量,它将 return 完整路径,但我只需要文件夹名称。我尝试使用 select -path
至少只显示路径,但它 returned 以及长度、模式等
我的目标是 return 只有这样的值:
folder 1
folder 2
folder 3
我正在使用 powershell 3.0
因此,如果我们要检查具有子结构 folder1\folder2
且父文件夹位于 C:\Temp
中的文件夹,那么我们将执行如下操作:
$destinations = (Get-Item "C:\Temp\*\folder1\folder2").Parent.Parent.Name
Get-Item "C:\Temp\*\folder1\folder2"
只会为 folder2
return System.IO.DirectoryInfo
个对象。我们获取这些对象并找到它们的祖父文件夹,只 return 它们的名字。
我正在构建一个脚本,用于将文件部署到多个特定文件夹。 使用此部分收集目标文件夹。
$destinations = Get-ChildItem "C:\this\is\*\my\path\"
所以我的脚本只有在文件夹有子文件夹“\my\path\”
时才会替换如果我现在检查我的变量,它将 return 完整路径,但我只需要文件夹名称。我尝试使用 select -path
至少只显示路径,但它 returned 以及长度、模式等
我的目标是 return 只有这样的值:
folder 1
folder 2
folder 3
我正在使用 powershell 3.0
因此,如果我们要检查具有子结构 folder1\folder2
且父文件夹位于 C:\Temp
中的文件夹,那么我们将执行如下操作:
$destinations = (Get-Item "C:\Temp\*\folder1\folder2").Parent.Parent.Name
Get-Item "C:\Temp\*\folder1\folder2"
只会为 folder2
return System.IO.DirectoryInfo
个对象。我们获取这些对象并找到它们的祖父文件夹,只 return 它们的名字。