Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 带自定义排序表达式的Powershell排序_Sorting_Powershell - Fatal编程技术网

Sorting 带自定义排序表达式的Powershell排序

Sorting 带自定义排序表达式的Powershell排序,sorting,powershell,Sorting,Powershell,我有一个包含编号目录的目录: Archive |-1 |-2 |-3 |-... 我需要创建下一个目录。我现在正在做的事情 $lastArchive = ls .\Archive | sort Name | select -Last 1 $dirName = '1' if($lastArchive) { $dirName = ([int]$lastArchive.Name)+1 } 这当然会失败,一旦我们得到10,排序规则遵循1后,而不是9。我需要排序表达式实际上是[int]$\

我有一个包含编号目录的目录:

Archive
 |-1
 |-2
 |-3
 |-...
我需要创建下一个目录。我现在正在做的事情

$lastArchive = ls .\Archive | sort Name | select -Last 1
$dirName = '1'
if($lastArchive) {
  $dirName = ([int]$lastArchive.Name)+1
}

这当然会失败,一旦我们得到10,排序规则遵循1后,而不是9。我需要排序表达式实际上是
[int]$\uName
-我该怎么做?

我想您需要更改第一行,如下所示:

$lastArchive = ls .\Archive | 
               Sort-Object -property @{Expression={[int]$_.Name}} | 
               Select-Object -Last 1
然后,您可以按如下数字顺序创建下一个目录:

mkdir ([int]$lastArchive.Name + 1).ToString()