简体   繁体   中英

Powershell rename multiple files

Example "rename multiple files" gives us this:

Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace '.txt','.log' }

But I need something like this:

Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace '.txt','someArray[$i]' }

How can I do that?

Simple. Take the quotes off and add a $:

EDIT: Ok, here's my guess. I don't know what $textfile is, or what result you want exactly. [^.jpg] just means any character except those 4.

get-childitem *.jpg | 
Foreach {$i=0} {Rename-Item $_ -NewName ($_.name -replace 'jpg', $textfile[$i++]) -whatif}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM