I tried using the following code to rename a folder of files "C:\www\folderx" using a text list "..\list.txt", but I can't figure out how to get the current file index:
Get-Childitem C:\www\folderx | % {
$OldName = $_.name;
$NewName = (GC ..\list.txt)[<CURRENT INDEX SHOULD GO HERE>];
# Rename-Item -Newname $NewName;
Write-Output $("Renamed {0} to {1}" -f $OldName,$NewName);
}
(GC ..\list.txt)inside the foreach. You're re-reading the contents of list.txt for every file passed down the pipeline. You could put that in the begin block e.g.... | Foreach -Begin {$i=0;$c = gc ..\list.txt} {$newname = $c[$i++];...}