Powershell Sort-Object Name with numbers doesn't properly

前端 未结 4 1468
眼角桃花
眼角桃花 2021-01-06 04:23

I am trying to find .sql files in a folder and filtering them based on the last write time. Based on the last write time I got 4 files as output.

TestScript1         


        
4条回答
  •  醉梦人生
    2021-01-06 05:02

    Thanks for all your suggestions above for my question. After streamlining the suggestions, the code below worked well for my situation. This is helping me sort in the natural order like Windows Explorer does.

    $ToNatural= { [regex]::Replace($_, '\d+',{$args[0].Value.Padleft(20)})}
    $File= Get-ChildItem $FileLocation -Filter *.sql | Where-Object {$_.LastWriteTime -gt $datetime} | Sort-Object $ToNatural
    

提交回复
热议问题