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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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,我试图列出一个目录的内容,并尝试将它们排序为最近创建的文件夹文件。我使用下面的脚本,但它只给我一个项目,这是最近创建的。我想做的就是按asc或desc顺序列出所有文件夹 $content = get-childitem 'C:\Users\tim\Desktop\tim_test' write-output $content | Sort-Object LastWriteTime -Descending | Select-Object -First 1 “选择对象-第一个1”只提供第一个文件

我试图列出一个目录的内容,并尝试将它们排序为最近创建的文件夹文件。我使用下面的脚本,但它只给我一个项目,这是最近创建的。我想做的就是按asc或desc顺序列出所有文件夹

$content = get-childitem 'C:\Users\tim\Desktop\tim_test'
write-output $content |  Sort-Object LastWriteTime -Descending | Select-Object -First 1
“选择对象-第一个1”只提供第一个文件,要获取所有文件,请删除该文件。像这样:

$newPath = 'C:\Users\tim\Desktop\tim_test2'
$content = get-childitem 'C:\Users\tim\Desktop\tim_test' | Sort-Object LastWriteTime -Descending
Write-Host $content

# Part 2
$oldFile = $content | Select-Object -first 1
$prefix = Read-Host "Enter prefix"
$newFile = "$newPath\$prefix$oldFile"
Copy $file $newFile

类似的方法应该会奏效:)

非常感谢,但我忘了在我的问题中提到,在整理之后,我想将最新的文件或文件夹复制到一个新位置,但不知道如何做只是为复制部分添加了一行,将$newLocation替换为您希望复制文件的路径。有没有一种方法可以对输出进行编号例如,如果输出类似folder1 folder 2 folder 3,我希望将其编号为1.folder1 2.folder2,因为我希望用户输入编号,例如1或2,以便将该文件夹复制到新位置。感谢扫描一些关于请帮助处理最后一篇文章上述解决方案允许我在文件夹中添加前缀,例如1,该文件夹将被复制到新位置,但我希望在复制之前显示文件夹中的数字。或者简单地说,我想用目录内容显示编号,根据这些编号,我可以要求用户输入要复制到新位置的文件夹。