如何在PowerShell中使用连续的数字重命名每个.jpg文件名

苏帕杜帕

我对PowerShell或与此相关的任何Shell都是全新的。我试图找出一种将109张标记为IMG_3571的照片重命名为IMG_3679的方法。我想从236开始连续编号。我已经尝试了一些方法,这就是我现在的位置:

Get-ChildItem "C:\Files to Transfer\test"*.jpg | ForEach-Object -begin {$count=236} -process {rename-item -Path "C:\Files to Transfer\test" -NewName "$count"}

我收到此错误消息108次:

At line:1 char:95
+ ... } -process {rename-item -Path "C:\Files to Transfer\test" -NewName "$ ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Rename-Item], PSInvalidOperationException
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RenameItemCommand

同样,名为“ test”(包含所有照片)的文件也更改为236 ...

编辑:我想让文件名中没有“ IMG”。只有数字。

谢谢大家!这是做什么的:

Get-ChildItem "C:\Files to Transfer\test\*.jpg" | ForEach-Object -begin {$count=236} -process {rename-item -Path $_.fullname -NewName "$count.jpg";$count++}

格林德尔

你近了

您需要重命名$ _。$ _是Get-ChildItem正在提供的管道变量。您的输出文件需要IMG-作为前缀,并且您需要增加计数。

尝试这个:

Get-ChildItem "C:\Files to Transfer\test\*.jpg" | ForEach-Object -begin {$count=236} -process {rename-item -Path $_.fullname -NewName "$count.jpg";$count++}

在要尝试的事情上添加-WhatIf非常有用,这样您就可以看到将要发生的事情而无需实际执行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章