gpt4 book ai didi

windows - 在循环之前对目录进行排序 - PowerShell

转载 作者:可可西里 更新时间:2023-11-01 09:43:22 24 4
gpt4 key购买 nike

我需要按创建日期从最早到最新的顺序处理文件

这是正确的还是有更好的方法?

谢谢

Get-ChildItem -Path C:\Users\Tom\ -Filter "*.journal" | Sort-Object -Property CreationTime

ForEach ($sourcefile In $(Get-ChildItem $source | Where-Object { $_.Name -match "Daily_Reviews\[\d{1,12}-\d{1,12}\].journal" }))
{
#### Process files in order from oldest to newest
$file = $source+$sourcefile
}

最佳答案

简短回答:不,但你很接近。

排序(和其他效果)仅在管道期间存在,除非您将结果存储在变量中。所以你排序的第一行不用于你的下一行。但是,您可以像这样组合它们:

$source = "C:\Users\Tom\"   

Get-ChildItem -Path $source -Filter "*.journal" |
Where-Object { $_.Name -match 'Daily_Reviews\[\d{1,12}-\d{1,12}\].journal' } |
Sort-Object -Property CreationTime | ForEach-Object {
#### Process files in order from oldest to newest
$_.FullName
}

关于windows - 在循环之前对目录进行排序 - PowerShell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15957958/

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