Powershell:返回具有最大编号的文件名 [英] Powershell: return filename with highest number

查看:75
本文介绍了Powershell:返回具有最大编号的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个像这样的文件名列表:

Suppose I have a list of filenames like this:

Get-ChildItem "Antarctica Data *.xls"

Antarctica Data 03625516.xls
Antarctica Data 84327262.xls
Antarctica Data 16374175.xls
Antarctica Data 12804427.xls
Antarctica Data 17477809.xls
Antarctica Data 60943758.xls
Antarctica Data 93962083.xls
Antarctica Data 74412097.xls
Antarctica Data 81562648.xls
Antarctica Data 58371936.xls

如何使用Powershell返回具有最大数字的文件名字符串?

How can I use Powershell to return a string of the filename with highest number?

Antarctica Data 93962083.xls

推荐答案

由于名称仅因数字而异,因此您所需要做的就是对它们进行排序,然后得到最后一个:

Because the names only differ by the numbers, all you need to do is sort them and then get the last one:

Get-ChildItem "Antarctica Data *.xls" |
Sort-Object |
Select-Object -Last 1 -ExpandProperty Name

或更简洁地说:

(gci "Antarctica Data *.xls" | sort)[-1].Name

输出:

南极数据93962083.xls

Antarctica Data 93962083.xls

这篇关于Powershell:返回具有最大编号的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆