Php get childitem get subdir name追加到脚本目录路径

Php get childitem get subdir name追加到脚本目录路径,php,powershell,get-childitem,Php,Powershell,Get Childitem,我正在尝试编写一个PS脚本,以便在参数指定的目录中查找空目录。“空目录”不应包含任何文件和子目录 以下是脚本: param ( [parameter (mandatory=$true,position=0)] [string]$Path ) $dirInfo = get-childitem $Path -recurse | ? {$_.PSIsContainer -eq $True} | % {get-childitem $_} | Measure-Object $dirInfo |

我正在尝试编写一个PS脚本,以便在参数指定的目录中查找空目录。“空目录”不应包含任何文件和子目录

以下是脚本:

    param (
[parameter (mandatory=$true,position=0)]
[string]$Path
)
$dirInfo = get-childitem $Path -recurse | ? {$_.PSIsContainer -eq $True} | % {get-childitem $_} | Measure-Object 
$dirInfo | ? {$dirInfo.count -eq 0} |  Select-Object Fullname
在“C:\documents文件夹”上运行时,出现以下错误:

**get-childitem : Cannot find path 'C:\Documents\ManualScripts\accounts' because it does not exist.
At C:\Documents\ManualScripts\Check-no-file-and-subdir-dir.ps1:5 char:79
+ $dirInfo = get-childitem $Path -recurse | ? {$_.PSIsContainer -eq $True} | % {ge ...
+                                                                               ~~
    + CategoryInfo          : ObjectNotFound: (C:\Documents\ManualScripts\accounts:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand**
C:\documents下的每个子文件夹都有许多类似的错误。它将脚本本身所在的目录(C:\Documents\ManualScripts)附加到子目录名

我已经做了研究,但仍然不明白。欢迎您的任何意见。谢谢:)

在上面的帖子之后,我对脚本做了一些更改,但到目前为止仍然没有工作:

param (
[parameter (mandatory=$true,position=0)]
[string]$Path
)

$Dirs = Get-ChildItem $Path -recurse | ? {$_.PSIsContainer -eq $True} | ForEach-Object -Process {$_.FullName}  #get list of all directories with whole path

foreach ($Dir in $Dirs) {
$emptyDir = Get-ChildItem $Dir | Measure | where {$_.Count -eq 0} | select-Object
}
睡觉前,我相信我会有一点进步。现在的脚本是这样的:

param (
[parameter (mandatory=$true,position=0)]
[string]$Path
)
$Dirs = Get-ChildItem $Path -recurse | ? {$_.PSIsContainer -eq $True} | ForEach-Object -Process {$_.FullName}  #get list of all directories with whole path
#$Dirs | ForEach-Object {Get-ChildItem $_} | ForEach-Object {measure} | where {$_.Count -eq 0} | Select-Object $Dirs 
ForEach ($Dir in $Dirs) {
$emptyDir = Get-ChildItem $Dir | Measure | where {$_.Count -eq 0} | Select-Object
$emptyDir
}
如果我运行,输出中会有一些内容(尽管不是我所期望的)

类似于“Select Object”的东西会拾取“measure”的输出,而不是下面没有文件/子目录的目录的名称

试试看:

Get-ChildItem $Path -Recurse -Force | 
Where-Object {$_.PSIsContainer -and (Get-ChildItem $_.FullName -Force | Measure-Object).Count -eq 0}
Get-ChildItem $Path -Recurse -Force | 
Where-Object {$_.PSIsContainer -and (Get-ChildItem $_.FullName -Force | Measure-Object).Count -eq 0}