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
1 Answer