powershell脚本文件重命名帮助
我正在制作一个脚本,使用预先提供的前缀与增量 6 位值相结合来重命名文件夹中的文件,该值与前缀连接时给出文档标题。
我需要脚本从提供的文件夹中迭代文件列表,并使用每次递增编号的前缀更改每个文件名,其中初始提供的编号是第一个递增编号。
我很接近,但我遇到了一些错误,我不确定哪里出了问题。请指教。
Write-host "Please enter prefix:"
[String]$strPrefix = read-host
Write-host "Please enter incrimental value:"
[int]$intInc = read-host
Write-host "Please enter Files folder:"
[String]$strFiles = "C:\scripts\files"
#$items = Get-ChildItem -Path $strFiles
$items = $strFiles
$intInc
#for each file in $strFiles
foreach ($file in $items )
{
$newName = $strPrefix + ('0' * (6 - $intInc.ToSTring().Length)) + ($intInc++).ToString()
if ($extOnly.length -eq 0)
{
Rename-Item New-Name{$file -replace '$newName'}
}
else
{
Write-host "NewName $newName$extOnly"
Rename-Item New-Name{$file -replace '$newName$extOnly'}
} #end else
$file
}#end for
我想我已经很接近了,但有什么东西让它倒塌
Im making a script to rename files in a folder using a preprovided prefix combined with an incrimental 6 digit value which when concatenated with the prefix gives the document title.
I need the script to iterate through the file list from a provided folder and alter each file name with the prefix incrimenting the incrimental number each time with the initial provided number being the first incriment.
I am close but i have been having some errors and im not sure where im going wrong. please advise.
Write-host "Please enter prefix:"
[String]$strPrefix = read-host
Write-host "Please enter incrimental value:"
[int]$intInc = read-host
Write-host "Please enter Files folder:"
[String]$strFiles = "C:\scripts\files"
#$items = Get-ChildItem -Path $strFiles
$items = $strFiles
$intInc
#for each file in $strFiles
foreach ($file in $items )
{
$newName = $strPrefix + ('0' * (6 - $intInc.ToSTring().Length)) + ($intInc++).ToString()
if ($extOnly.length -eq 0)
{
Rename-Item New-Name{$file -replace '$newName'}
}
else
{
Write-host "NewName $newName$extOnly"
Rename-Item New-Name{$file -replace '$newName$extOnly'}
} #end else
$file
}#end for
I think im close but something is just making it fall over
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)