[英]Order of numbered files by get-childitem
我需要更改get-childitem返回目录中文件名的顺序,因为以特定方式处理它们很重要。 文件名具有以下格式:f_1.csv,f_2.csv,f_3.csv,f_4.csv,...,f_10.csv,f_11.csv等get-childitem返回的默认顺序为:f_1.csv ,f_10.csv,f_100.csv。
一种解决方案是将文件名更改为f_001.csv,f_002.csv,f_003.csv,但是我无法控制文件的创建方式,而且我不知道文件的编号(可能是数百,数千等)
我当前的代码是:
foreach($file in Get-ChildItem $path -Filter f_*.csv)
{
#process the files here
}
谢谢
像这样吗
Get-ChildItem -Filter f_*.csv |
sort @{Expression={[int]($_.name -replace 'f_(\d+).+','$1')};Descending=$false}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.