我找到了一个cmdlet,无论路径大小如何,都会返回所有文件。我想知道是否有一个等效的命令,无论路径大小如何都能获得所有文件夹?
Get-FolderItem
结合了robocopy和powershell,即使路径大于260的文件也会返回。
无论如何都要获取文件共享中的所有文件夹
答案 0 :(得分:1)
Get-FolderItem
使用robocopy
开关/NDL
从日志输出中排除目录,用于获取文件信息。它还可以使用/S
开关来递减而不是/E
只需更改$params
变量:
$params.AddRange(@("/L","/S","/NJH","/BYTES","/FP","/NC","/NDL","/TS","/XJ","/R:0","/W:0"))
到
$params.AddRange(@("/L","/E","/NJH","/BYTES","/FP","/NC","/NFL","/TS","/XJ","/R:0","/W:0"))
现在,Robocopy将列出目录,而不是文件。由于目录的输出与文件略有不同,因此您还必须稍微更改解析逻辑。
更改
If ($_.Trim() -match "^(?<Size>\d+)\s(?<Date>\S+\s\S+)\s+(?<FullName>.*)") {
$object = New-Object PSObject -Property @{
ParentFolder = $matches.fullname -replace '(.*\\).*','$1'
FullName = $matches.FullName
Name = $matches.fullname -replace '.*\\(.*)','$1'
Length = [int64]$matches.Size
LastWriteTime = [datetime]$matches.Date
Extension = $matches.fullname -replace '.*\.(.*)','$1'
FullPathLength = [int] $matches.FullName.Length
}
$object.pstypenames.insert(0,'System.IO.RobocopyDirectoryInfo')
Write-Output $object
}
到
If ($_.Trim() -match "^(?<Children>\d+)\s+(?<FullName>.*)") {
$object = New-Object PSObject -Property @{
ParentFolder = $matches.fullname -replace '(.*\\).*','$1'
FullName = $matches.FullName
Name = $matches.fullname -replace '.*\\(.*)','$1'
}
$object.pstypenames.insert(0,'System.IO.RobocopyDirectoryInfo')
Write-Output $object
}
那应该这样做