簡體   English   中英

Powershell 根據上次修改日期重命名文件

[英]Powershell to rename files based on laast modified date

我想在現有文件名前添加一個增量數字。 但是,我想根據他們的日期修改信息與他們的名字重命名他們。

Sort-Object LastWriteTime | [ref]$i = 1; gci -file | Rename-Item -NewName {'{0:D} . {1}' -f $i.Value++, $_}

延遲綁定腳本塊之外的增量:

$inc = 1 # Increment
Get-ChildItem -File | Sort LastWriteTime | Foreach-Object {
    $_ | Rename-Item -NewName { "{0} . {1}" -f $inc,$_ } -WhatIf
    $inc++
}

如果您對重命名結果感到滿意,請刪除-WhatIf

或者像這樣在增量變量中使用腳本范圍:

$inc = 1
Get-ChildItem -Path 'TheFolderWhereTheFilesAre' -File | 
    Sort-Object LastWriteTime | 
    Rename-Item -NewName {'{0} . {1}' -f $script:inc++, $_.Name} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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