簡體   English   中英

按get-childitem編號的文件順序

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM