gpt4 book ai didi

powershell : find subdirectories with the longest paths

转载 作者:行者123 更新时间:2023-12-02 23:18:00 25 4
gpt4 key购买 nike

我想找到给定目录中子目录中最长的路径,因为我遇到了这个错误:

The specified path, file name, or both are too long.
The fully qualified file name must be less than 260 characters,
and the directory name must be less than 248 characters.

这是我尝试过的:

$dir = "\\share\server\toto" 
Get-ChildItem -Path $dir -Recurse -Directory |
Select-Object Name,FullName,
@{Name='FileCount';Expression = {(Get-ChildItem -Path $_.FullName -File -Recurse| Measure-Object).Count}} `
| Format-List *

但这给了我所有目录。

相反,我想找到路径最长的前 5 个目录。

最佳答案

这将返回具有最长路径的 5 个目录:

Get-ChildItem -Path $dir -Recurse -Directory | % { $_.FullName } | Sort-Object { $_.Length } -Descending | Select -first 5

关于powershell : find subdirectories with the longest paths,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59840453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com