在powershell中,如何按目录名的长度对目录进行排序? [英] In powershell how do sort directories by the length of the directory name?
本文介绍了在powershell中,如何按目录名的长度对目录进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经阅读了很多示例,但似乎无法找到一个语法来按照完整目录名的长度对PowerShell中的目录列表进行排序。
这就是我所拥有的:
$ folderNamePatterns = @(bin,obj)
$ deleteFolderList = Get-ChildItem -Path $ rootFolder -Recurse -Directory -Include($ folderNamePatterns)| Sort-Object -Property DirectoryName.Length
写输出文件夹列表是:
for($ i = 0; $ i -lt $ deleteFolderList.Count; $ i ++)
{
写输出$ deleteFolderList [$ i] .FullName
}
它没有错误,但它没有'排序清单。
我必须遗漏一些令人沮丧的简单事。谁能告诉我什么?
亲切的愿望~Patrick
我试过的:
我已经为-Property参数尝试过所有种类。
解决方案
folderNamePatterns = @(bin,obj)
deleteFolderList = Get-ChildItem -Path
rootFolder -Recurse -Directory -Include(
I've read plenty of examples but don't seem to be able to find a syntax to sort a list of directories in PowerShell by the length of the full directory name.
This is what I have:
$folderNamePatterns = @( "bin", "obj" ) $deleteFolderList = Get-ChildItem -Path $rootFolder -Recurse -Directory -Include ( $folderNamePatterns ) | Sort-Object -Property DirectoryName.Length Write-Output "Folder list is:" for( $i=0; $i -lt $deleteFolderList.Count; $i++ ) { Write-Output $deleteFolderList[ $i ].FullName }
It gives no error but it doesn't sort the list.
I must be missing something frustratingly simple. Can anyone please tell me what?
Kind wishes ~ Patrick
What I have tried:
I've tried all sorts for the -Property argument.
解决方案
folderNamePatterns = @( "bin", "obj" )
deleteFolderList = Get-ChildItem -Path
rootFolder -Recurse -Directory -Include (
这篇关于在powershell中,如何按目录名的长度对目录进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文